View Single Post
  #2   Spotlight this post!  
Unread 16-11-2009, 09:13
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: Help with a simple function

All files in a WindRiver project are compiled and linked together. To call any of the functions in another file you just invoke its name. In order to let each file know what is available in the others at compile time you usually add prototypes to all the functions in a header file. So if I had a primary.cpp file and german.cpp file I would add a header file, you could call it anything you want and put all the things you want available from every other file in there.

The preprocessor directives prevent the header file from being invoked multiple times during preprocessing

The simple example shows a set of functions in primary that call some functions in german to do math processing. By letting each file know what is available via a header file #include you can access any function from any file in the project. (pick up a good book on C++ for your team, like the one of O'Reilly titles, it will be handy for questions like this as you progress into more and more complex programs)

primary.cpp:

#include myHeader.h

int pfunc1(int arg1){
<stuff>
int someInt = gfunc(arg1);
return someInt;
}
float pfunc2(float arg1){
<stuff>
float someFloat = gfunc(arg1);
return someFloat;
}

german.cpp:

#include myHeader.h

int gfunc1(int arg1){
<stuff>
int someInt = arg1 / 2;
return someInt;
}
float gfunc2(float arg1){
<stuff>
float someFloat = arg1 * 3.1415926;
return someFloat;
}

myHeader.h:
#ifndef __myheaderh
#define __myheaderh

//function prototypes from primary.cpp
int pfunc1(int arg1);
float pfunc2(float arg1);

//function prototypes from german.cpp
int gfunc1(int arg1);
float gfunc2(float arg1);

#endif

Last edited by omalleyj : 16-11-2009 at 09:16.
Reply With Quote