Where to specify preprocessor directives in visual studio?

Trying to define preprocessor directives in Visual Studio 2012.

#define FLAG
....
#endif

      

But not sure where to include this FLAG

in visual studio - C #. I remember how it was pointed out in C ++ projects.

Any thoughts?

+3


source to share


1 answer


You have two options:

  • Define it at the code file level. At the beginning of the file, write #define FLAG

    . You cannot place anything else (other than comments and blank lines) before directives define

    . As Ron Beyer points out, a directive defined in a file only exists for that file.

  • Define it at the project level. Right click on the project in Solution Explorer, select Properties, then Build tab, then browse Compile Conditional Symbols. There are several characters separated by commas: FLAG,FOO,BAR

    . Note that this list of symbols depends on the project configuration (there is a config selector on the same tab).



And since EBrown will align define

doesn't work the same way in C # as it does in C. In C #, you just declare that the symbol exists, but you can't assign a value to it. Hence, the only use of these symbols is for directives #if FLAG

and for conditional attribute .

+9


source







All Articles