Jump to content
  • Advertisement
Sign in to follow this  
chadsxe

Preprocessor directive questions...

This topic is 4174 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a question about preprocessor directives. Lets say I have something like this #define WINDOWS #ifdef WINDOWS #include <d3d9.h> ... #endif #ifdef SDL #include "SDL/SDL.h" ... #endif in a source file called main.cpp. I then have another class set up in a diffrent source file in which I want to use that one "#define WINDOWS" located in main.cpp. Basically I want the "#define WINDOWS" to be global across all other sources and classes. That way I can switch that #define in one place and not in every source file. ERrrrr does that make sense. Any advice on how to accomplish this? Regards Chad

Share this post


Link to post
Share on other sites
Advertisement
There should be a way to accomplish that through the compiler/ide. That's typically the way that UNICODE is defined. There usually is a line in the make file that tells compiler/preprocessor about such global defines. Check your compiler/ide docs for details.

Share this post


Link to post
Share on other sites
Well, in addition to the method that LessBread gave, you could make a header file and include it in every .cpp file. This, however, is clumsy so the first method should be preferred. In order to make a global define with VC++ 2005 go to:
Project->Properties

Configuration Properties -> C++ -> Preprocessor

Under "Preprocessor Definitions" you can enter your define.

Just so you know, WIN32 already exists for windows programs, so you can probably get away with just using that :)

edit: I don't use g++, but I'm sure there are similar methods.

Share this post


Link to post
Share on other sites
adding to what nobodynews said, that one header that you include in all source files, if it's not going to be changed very often, should be your precompiled header file. that's where i always define my WINVER and _WIN32_WINNT macros (right before i include windows.h, commctrl.h, etc.) and all my other global macro hackery.

Share this post


Link to post
Share on other sites
Quote:
Original post by chadsxe
Sorry...but you lost me. I am using V++ 2005 and g++.


This shouldn't be too bad. You can pass macro definitions to g++ easily, using the "-Dmacro=value" syntax or something like that (check man page). You can probably do the same on the visual studio IDE.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!