View Single Post
  #3   Spotlight this post!  
Unread 05-02-2004, 17:44
Adam Shapiro's Avatar
Adam Shapiro Adam Shapiro is offline
Registered User
FRC #0555 (Montclair Robotics)
Team Role: Alumni
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Montclair, NJ
Posts: 401
Adam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud ofAdam Shapiro has much to be proud of
Send a message via AIM to Adam Shapiro
Re: Global Variables, anyone?

The easiest way (in my opinion) is to use the extern keyword. You can do this using two methods:
  1. Declare the variable in one file and declare it in each additional file in which it must be used with the extern keyword.
  2. Declare the variable in a file and declare it using the extern keyword in a header file to be included in all files requiring the variable.
I always find that it is easiest to use method two as follows:
Code:
main.c (or another file)
#include "globals.h"
int iGlobalVar;
iGlobalVar=1;

globals.h
extern int iGlobalVar;

usingglobals.c
#include "globals.h"
if(iGlobalVar==1)printf("Awesome! It worked! ;)");
Hope this helps.
__________________
Mentor to Teams 555, 1929, and 2070!
Currently working in hardware design at Cisco.
Cornell University DARPA Urban Challenge - http://www.cornellracing.com
Co-Captain Team 555 - 2003,2004,2005
Trust, Love, and Magic