Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » #define -WARNiNG

This thread is locked; no one can reply to it. rss feed Print
#define -WARNiNG
type568
Member #8,381
March 2007
avatar

I am using VS6, and after changing my #define (macros..) values, I got warnings, of macro redefinition. If I comment the #defines, the game works, as if I would be using my previous definitions.

First time, I defined the values, I had no warnings, no errors. It looks like the macros are stored somewhere else. I am using "win32 console application".

The Code:

#define USE_CONSOLE
#include <ALLEGRO.H>
#include <MATH.H>

#define RESOX  800
#define RESOY  800
#define RESOZ  800

#define MiD    400
#define LENGTH  200
#define PER_0 1600

The warnings:

D:\nvm\C\3DA3b\MAiN n ONLY.cpp(6) : warning C4005: 'RESOY' : macro redefinition
        d:\nvm\c\3da3b\main n only.cpp(6) : see previous definition of 'RESOY'
D:\nvm\C\3DA3b\MAiN n ONLY.cpp(7) : warning C4005: 'RESOZ' : macro redefinition
        d:\nvm\c\3da3b\main n only.cpp(7) : see previous definition of 'RESOZ'
D:\nvm\C\3DA3b\MAiN n ONLY.cpp(9) : warning C4005: 'MiD' : macro redefinition
        d:\nvm\c\3da3b\main n only.cpp(9) : see previous definition of 'MiD'
D:\nvm\C\3DA3b\MAiN n ONLY.cpp(10) : warning C4005: 'LENGTH' : macro redefinition
        d:\nvm\c\3da3b\main n only.cpp(10) : see previous definition of 'LENGTH'

Help please, i hate getting warnings, also slows down the progress when i get something important.

Thanks..

GullRaDriel
Member #3,861
September 2003
avatar

You have them defined somewhere elese in your code.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

type568
Member #8,381
March 2007
avatar

It can't be, there's only 1 file. Here's all the project. (a lot of other files, made auto by VS..)

Also, the code given is the top(of the file). And, pressing F4, following the message directs me there..

LennyLen
Member #5,313
December 2004
avatar

make a test project, and see if you get the same errors if you make the same defines. If so, they're reserved words for VS6, for some reason.

edit: never mind. The problem is that you don't use header guards, and most of your .cpp files include header.h, wich in turn includes #define.h. So the defines get included multiple times.

type568
Member #8,381
March 2007
avatar

Linking...

test1.exe - 0 error(s), 0 warning(s)

I made a new project, empty, made a file, copied there all the source, and it's fine.

I changed values of the macros, and didn't get any warning.

LennyLen
Member #5,313
December 2004
avatar

See my edit above.

type568
Member #8,381
March 2007
avatar

Oh. How do I use them though?

LennyLen
Member #5,313
December 2004
avatar

In the define.h file, do this:

#ifndef DEFINE_H
#define DEFINE_H
...
rest of header file here
...
#endif

Similarly for EVREY header file that will be included by more than one file. The exact term you define doesn't really matter, but what I did above is standard (taking the header name, capitalizing it, and replacing the . with _).

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

#include <ALLEGRO.H>
#include <MATH.H>

No, it's "allegro.h" and "math.h", in lowercase. Windows doesn't mind, but every other operating system does.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

type568
Member #8,381
March 2007
avatar

Thanks, though in my case than doesn't matter.

Go to: