View Single Post
  #5   Spotlight this post!  
Unread 08-02-2008, 17:00
wireties's Avatar
wireties wireties is online now
Principal Engineer
AKA: Keith Buchanan
FRC #1296 (Full Metal Jackets)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Rockwall, TX
Posts: 1,170
wireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond reputewireties has a reputation beyond repute
Send a message via AIM to wireties
Re: Multiple Definitions

You want the compiler to encounter only one declaration for the variable as it processes the set of source source files. Your technique above is designed to prevent multiple references or forward references to be encountered , not multiple variables. I'm sure your custom_routines.h file is processed when you compile multiple separate source files.

So do his, change the statement in custom_routines.h to an external reference and declare storage for the variable in ONLY one source file.

In custom_routines.h, do this:

#ifndef _CUSTOM_ROUTINES_H_
#define _CUSTOM_ROUTINES_H_
...
extern bool ReleasingBall;
...
#endif

In custom_routines.c, do this:

....
#include <timer.h>
#include "custom_routines.h"

bool ReleasingBall; // defined only here!

// function definitions
...

One last thing, it is generally considered bad style to define storage in a header file for exactly the reason you have encountered.

HTH