Go to Post Please look around the forum, I believe this clue is already under discussion and has been overly dissected. - ttldomination [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 22-01-2008, 22:34
robbrad robbrad is offline
Registered User
FRC #1875 (Autonomato Autonomatons)
Team Role: Electrical
 
Join Date: Jan 2007
Rookie Year: 2005
Location: Titusville
Posts: 37
robbrad is an unknown quantity at this point
Global Variable Placement

I've tried to insert global variables in various places in Kevin's code only to get stack overflow, code errors (RC), sytax errors, compiler crashes and general system crashes. Where do you all put your global variables. I'm interested in global only. I'd like to minimise passing information between functions. Thanks
__________________
  #2   Spotlight this post!  
Unread 23-01-2008, 00:50
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Global Variable Placement

Quote:
Originally Posted by robbrad View Post
I've tried to insert global variables in various places in Kevin's code only to get stack overflow, code errors (RC), sytax errors, compiler crashes and general system crashes. Where do you all put your global variables. I'm interested in global only. I'd like to minimise passing information between functions. Thanks
A good practice is to declare a variable outside of any function and then declare the variable as "extern" within the associated header file. So for example, at the top of teleop.c I declare a variable:

// this allocates memory
unsigned int foo;

Then in teleop.h I declare the variable again with the keyword extern:

// no memory is allocated, but lets the compiler know the name (foo)
// and type (unsigned int), and that it is located in another source file
extern unsigned int foo;

Then include teleop.h at the top of each source file that needs to use foo. The line will look like this:

#include "teleop.h"

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
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
Global news tonight Mark Rozitis FIRST In the News... 3 08-04-2008 21:24
GTR on Global news! Mark Rozitis General Forum 26 08-04-2007 21:00
Global Constants Ryan Cumings Programming 17 08-02-2004 19:05
Global Variables, anyone? Darkman_X000 Programming 3 05-02-2004 22:11


All times are GMT -5. The time now is 09:15.

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