Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Stupid Variable question.... (http://www.chiefdelphi.com/forums/showthread.php?t=44414)

BillyJ 20-02-2006 15:54

Stupid Variable question....
 
I have a stupid question about my code that just wont work..........

In all my code I've always setup the variables I need in user_routines_fast.c for auto, and user_routines.c for the main.

Now I want to use the same variable in both files, how could I go about doing this?


Thanks

Greg Ross 20-02-2006 16:05

Re: Stupid Variable question....
 
Quote:

Originally Posted by BillyJ
I have a stupid question about my code that just wont work..........

In all my code I've always setup the variables I need in user_routines_fast.c for auto, and user_routines.c for the main.

Now I want to use the same variable in both files, how could I go about doing this?


Thanks

Declare your variable as usual in whichever .c file, and then add an extern in the other .c file where you want to access the variable. Example:

Code:

user_SerialDrv.c:55: unsigned char aBreakerWasTripped; // Creates the variable.


user_routines.c:22: extern unsigned char aBreakerWasTripped; // Tells the compiler the variable exists in another module.


rappo 20-02-2006 16:07

Re: Stupid Variable question....
 
Or, you can keep the variables in their files and add a definition in user_routines.h

example:

Code:

#define LEFT p1_y

Keith Watson 20-02-2006 19:49

Re: Stupid Variable question....
 
Typically the extern is put in a .h file that is included in all the .c files you want to use it in.


All times are GMT -5. The time now is 19:27.

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