|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
How do you tell your program to switch to a different file? For example, you want the program to start in Primary.cpp and then go to German.cpp.
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
Re: Help with a simple function
Quote:
Also, isn't #include used for to include libraries? |
|
#4
|
||||
|
||||
|
Re: Help with a simple function
I figured it out-you just need the prototypes not the #include. Thanks though.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with simple program | Rob Stehlik | C/C++ | 2 | 23-10-2009 15:00 |
| Problem with easy C CameraTracking function | mjveld1018 | Programming | 9 | 16-02-2007 19:36 |
| Issues with Generate_Pwms() function | pantherico | Programming | 1 | 30-01-2005 16:24 |
| help with simple project | erikh98 | Technical Discussion | 8 | 27-08-2004 11:24 |
| Simple problem with variables | sear_yoda | Programming | 4 | 05-02-2004 09:12 |