vico
vico

Reputation: 18191

Managing code with using #define

I have several source and header files that contains code that should be compiled dependent on the same option. That option might be set with

#define myOption

To be visible this option in all my files I need to put it in place where all files could see it. I see only one way - place this option in special header file and include it to all source and header files. Is there any other way to solve my problem? What is the best practices with code organisation?

UPD

In comments I found option that header file that contains myOption might be stdafx.h. But this is not good practice as far I can see because in CPP projects with enabled precompile header I can have for example some units with C code with turned off precompiled header.

Upvotes: 1

Views: 164

Answers (1)

gomons
gomons

Reputation: 1976

As @Paranaix mention you can provide preprocessor definition for compiler as command line argument like -DmyOption. Let suppose you use Visual Studio, you can open project properties->C/C++->Preprocessor->Preprocessor Definitions and place myOption in that list. It automatically add -DmyOption argument for compiler. So every source file in your project now can check that option.

Upvotes: 2

Related Questions