Go to Post And, if you don't know what something means, say so, we'll be happy to explain. - DonRotolo [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Spotlight this post!  
Unread 02-03-2005, 19:38
ace123's Avatar
ace123 ace123 is offline
Registered User
AKA: Patrick Horn
FRC #0008 (Paly Robotics - http://robotics.paly.net/)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Palo Alto, CA
Posts: 50
ace123 has a spectacular aura aboutace123 has a spectacular aura about
Send a message via AIM to ace123
Re: Static Variables

declare the variable(s) you want to use outside of a function (outside any brackets).
Then, move the extern line(s) into a .h file (user_routines.h)
The extern lines are optional, and are only needed if you want to use them in more than one file (user_routines.c and user_routines_fast.c for autonomous)

After that, you can read and write to them from any function:

user_routines.c
Code:
#include "user_routines.h"
...
...
/* Only declare and initialize global variables *once*.*/
int x=0;
int y=0;
void func1(void) {
    x=1;
}
void func2(void) {
    y=x;
}
void Default_Routine(void) {
    /* caution: do not declare the global variables (or variables with the same name) inside a function again. This may cause strange behaviour if done by accident, and will not produce an error or even a warning in most cases.*/
    // int x; <-- NO COMPILE ERROR! 
    pwm01=y+127;
    pwm02=x+127;
}
user_routines.h
Code:
...
...
/* The extern allows *global variables* declared in one file to be usable in any other file. */
extern int x;
extern int y;
void func1(void);
void func2(void);
void Default_Routine(void);
__________________
-Patrick Horn, Paly Robotics

Check out the space simulator called Vega Strike, modelled after the space simulator games Elite and Wing Commander. It's Open Source too!
If you have ever played Wing Commander, or especially Privateer, and had a feeling of nostalga derived from the you will enjoy these two Vega Strike mods: Privateer Gemini Gold and Privateer Remake!
I'm working on adding multiplayer support this year...
 


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
Need help with Variables ? David Bryan Programming 5 23-02-2004 07:42
Joystick Variables fred Programming 8 20-02-2004 10:58
Simple problem with variables sear_yoda Programming 4 05-02-2004 09:12
VB Program to monitor robot variables DanL Programming 7 15-02-2002 22:35


All times are GMT -5. The time now is 00:02.

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