View Full Version : 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
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:
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.
Or, you can keep the variables in their files and add a definition in user_routines.h
example:
#define LEFT p1_y
Keith Watson
20-02-2006, 19:49
Typically the extern is put in a .h file that is included in all the .c files you want to use it in.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.