Go to Post I worship whoever cleans the robotics room. - John Gutmann [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 15-11-2009, 20:49
karatekid's Avatar
karatekid karatekid is offline
Registered User
AKA: Cole
FRC #0662 (Rocky Mountain Robotics)
Team Role: Programmer
 
Join Date: Nov 2009
Rookie Year: 2009
Location: Colorado Springs, Colorado
Posts: 120
karatekid has a spectacular aura aboutkaratekid has a spectacular aura aboutkaratekid has a spectacular aura about
Question Help with a simple function

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.
__________________
YOU JUST LOST THE GAME!
Reply With Quote
  #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
  #3   Spotlight this post!  
Unread 16-11-2009, 16:19
karatekid's Avatar
karatekid karatekid is offline
Registered User
AKA: Cole
FRC #0662 (Rocky Mountain Robotics)
Team Role: Programmer
 
Join Date: Nov 2009
Rookie Year: 2009
Location: Colorado Springs, Colorado
Posts: 120
karatekid has a spectacular aura aboutkaratekid has a spectacular aura aboutkaratekid has a spectacular aura about
Re: Help with a simple function

Quote:
Originally Posted by karatekid View Post
I was looking at buying a copy of WindRiver to use on my personal laptop, but I wanted it to be the same WindRiver that is used by First. I went to the WindRiver website, but I saw there were several different versions to choose from. Which one should I use?
If you can answer this question, that would help. How would you do it with regular ecplise?

Also, isn't #include used for to include libraries?
__________________
YOU JUST LOST THE GAME!
Reply With Quote
  #4   Spotlight this post!  
Unread 17-11-2009, 10:48
karatekid's Avatar
karatekid karatekid is offline
Registered User
AKA: Cole
FRC #0662 (Rocky Mountain Robotics)
Team Role: Programmer
 
Join Date: Nov 2009
Rookie Year: 2009
Location: Colorado Springs, Colorado
Posts: 120
karatekid has a spectacular aura aboutkaratekid has a spectacular aura aboutkaratekid has a spectacular aura about
Re: Help with a simple function

I figured it out-you just need the prototypes not the #include. Thanks though.
__________________
YOU JUST LOST THE GAME!
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 13:55.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi