Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how i create header file from C++

Status
Not open for further replies.

J_expoler2

Member level 4
Joined
May 10, 2003
Messages
77
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
619
c++ create header file

Hi
i want create my functions how i create header file from C++
it doesn't work input of function is array 3000 data output is array 3000 data it compile pass but link fail
:cry:
//***************************
// header file is conv.h
extern con(double *x);
extern H1[];

//**************************
// source file conv.c
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <conv.h>
double x[N];
double H1[N];
int n;
void con(double *x)
{
for(n=0;n<N;n++)
{
H1[n] = aa0*(x[n]-H1[n-2])+aa1*(x[n-1]-H1[n-1])+x[n-2];
}
}

thanks
 

c++ creating header files

A headerfile is normally used as a definition of stuff you want to make available in other C/C++ files.

when you have this in your C file:
These are implementations and definitions (meaning it compiles/creates code/data which is available for the linker)

Code:
const int N  = 3000;
const int aa0 = 10;
const int aa1 = 12;
double H1[N];

void con(double *x) // tty using an stl vector here!  Or at least make it const!!!
  { 
    for(int n=0;n<N;n++) 
      { 
        H1[n] = aa0*(x[n]-H1[n-2])+aa1*(x[n-1]-H1[n-1])+x[n-2]; 
      } 
  }

To be able to use these function and variable in other C/C++ files you have to describe them (this can be done in the other C/C++ file directly or better in a headerfile which can be included where needed).

RULE 1: ALWAYS USE GUARDING STATEMENTS IN HEADER FILES!!!

Code:
#ifndef MyHeaderFilesUniqueName_h_
#define MyHeaderFilesUniqueName_h_
// Above are the guarding statements.
// These prevent multiple inclusion of headerfiles
// and will spare you from very strange compile and link errors!

//the code

extern double H1[N]; 
/* this makes the array H1 available in all files that include this header file.
  The array isn't defined here (meaning no memory is allocated here)  It's just a definition that somewhere out there in your code, there is an array defined with the name H1.  The linker will look for it at link time.  When it isn't found anywhere, it gives link errors!
  A good guideline in C++ is to use as less global variables as possible. /*

void con(double *x);
/* This is what's called a function prototype.  It merely describes that a function like this is available somewhere and can be used.  The linker will look for this function and give a link error when it isn't found! */

#endif // MyHeaderFilesUniqueName_h_

I hope this helps a bit!
But i suggest you read a good C++ book before you continue!
Programming ain't just making it compile! When you don't understand what you're doing you won't be able to write working code!

Antharax

Antharax
 

making a header file in c++

while i admire your enthusiasm in learning C++ creating header files to do your bidding is not as useful as one might assume. The functions you are trying to create may also be included directly into the program withought the use of a header file and used from there.

Header files are created by advanced programers to keep their programs and variables organized by using structs and classes. Mathematical formulas such as compound intrest formulas or projectile motion formulas would be better off written into the program directly with variables being assighned directly to them, or if these formulas are used multiple times (possibly between 5 and 100 times) the formula may deserve to have a function dedicated to it within your main program. However, if the function you are creating needs to be used by multiple programs then, it may be worthy of a header file.

sorry if i'm kicking an old topic. everyone.

-jrud out-
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top