Go to Post So as you're thinking about this, think simple. - Cyberguy34000 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-02-2006, 15:54
BillyJ BillyJ is offline
Registered User
no team
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Texas
Posts: 13
BillyJ is an unknown quantity at this point
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
  #2   Spotlight this post!  
Unread 20-02-2006, 16:05
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
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.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #3   Spotlight this post!  
Unread 20-02-2006, 16:07
rappo's Avatar
rappo rappo is offline
Drag and drop that for loop!
FRC #0696 (Circuit Breakers)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Glendale, California
Posts: 49
rappo is a jewel in the roughrappo is a jewel in the roughrappo is a jewel in the roughrappo is a jewel in the rough
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
__________________
Team 696 Circuit Breakers
2006 LA Regional - Radio Shack Innovation in Control Award
  #4   Spotlight this post!  
Unread 20-02-2006, 19:49
Keith Watson Keith Watson is offline
Registered User
FRC #0957 (WATSON)
Team Role: Mentor
 
Join Date: Feb 2006
Rookie Year: 2006
Location: Wilsonville, OR
Posts: 112
Keith Watson is just really niceKeith Watson is just really niceKeith Watson is just really niceKeith Watson is just really nice
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.
__________________
Keith Watson - Professional Software Engineer
No relation to "Kevin" Watson, who created the camera tracking code.
Closed Thread


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
Camera variable scope question Validius Programming 1 28-01-2006 09:24
Stupid question but... Adam Y. Math and Science 6 16-02-2004 19:29
Really stupid question psychoCHIPMUNKK Kit & Additional Hardware 3 15-02-2004 00:26
stupid question x10 Tom Bottiglieri CD Forum Support 1 04-02-2004 22:40
And here's Fishy for stupid question time.. A. Leese Chairman's Award 1 23-10-2001 22:38


All times are GMT -5. The time now is 03:34.

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