Brian Espenschied

HC08: Global Variables and constants

Discussion created by Brian Espenschied on Jun 6, 2006
Latest reply on Feb 26, 2010 by CompilerGuru
I recently changed from V3.2 to 5.0 Codewarrior for the HC08. I am having trouble getting code to compile in the new version that worked in the old. My main code is located in a file called pacer.c. I have global var's that I use in my main routine and other modules called utilities.c and events.c. I put all my global vars and constants in a file called globals.h
I now get duplicate definitions when I include the globals.h file in the utilities.c module. If I do not include the globals.h file in the utilities.c module I get not declared errors for the variables. I have been programming C for a few years now and still seem to have troubles with this. I have checked all my books and reference material and I keep getting different answers. Some say the vars have to be declared as external in the header file and declared as just the type in the module they are used in. Then others say just the opposite. It works better in codewarrior if I use only the type as byte, int, etc in the header file (globals.h) and the extern in the module it is being used in. Is there a general discussion on this somewhere. I do not mind the research. I just cant figure out what is the correct (ANSI) method. Here is a cop of my globals.h file
#ifndef __globals
#define __globals
// Global variables
unsigned int Delay10ms;
byte WaitTime;
byte ProgramCount;
byte Level;
byte key;
byte Count2Sec;
byte kb_flag; //used to indicate keyboard status
byte keyval; //Value of pressed key
//setup for the different Modes used in the program
byte Mode;
#define run   0          /* Run Mode        */
#define program  1          /* Program Mode        */
#define sleep  3   /* Sleep Mode */

#define Key_Mode  1   /* Keyboard Value for mode switch */
#define Key_Up   2   /* Keyboard Value for Up switch */
#define Key_Down  4   /* Keyboard Value for Down switch */
#define Key_Standby 8   /* Keyboard Value for program switch */

#endif //__globals
Any ideas? Thanks!

Message Edited by CrasyCat on 2007-04-13 02:20 PM