View Single Post
  #4   Spotlight this post!  
Unread 27-01-2008, 18:02
jacobhurwitz jacobhurwitz is offline
Registered User
FRC #0449 (Blair Robot Project)
Team Role: Programmer
 
Join Date: Jan 2008
Rookie Year: 2007
Location: Maryland
Posts: 45
jacobhurwitz has a spectacular aura aboutjacobhurwitz has a spectacular aura aboutjacobhurwitz has a spectacular aura about
Re: Global variable question

A simple way to make sure this works in all files is to add this to a header (.h) file:

Code:
#ifdef DEFINE_VARS
extern int foo;
#endif

#ifndef DEFINE_VARS
#define DEFINE_VARS
int foo;
#endif
So, what does this do? You have some macro, DEFINE_VARS. If it has already been defined, you declare extern int foo. If it hasn't been defined, you define it and declare int foo. This way, foo is external for all files but one.

I hope this helps.