Preprocessor Directives
-
Hi, First of all, I'm so sorry for asking such a n00b question, but in VC++ 8 I could found the preprocessors directives easily but with C# for VS2008 I have no idea where they are... What directive should I test to be sure the application was compile in Windows?
#if WIN
? Thanks, Dirso
-
Dirso, Well since .NET only runs in a Windows environment, why would you need to check this...
Regards, Gareth. (FKA gareth111)
-
Hi, First of all, I'm so sorry for asking such a n00b question, but in VC++ 8 I could found the preprocessors directives easily but with C# for VS2008 I have no idea where they are... What directive should I test to be sure the application was compile in Windows?
#if WIN
? Thanks, Dirso
Hi, AFAIK there are no predefined symbols in C#. So if your code includes a
#if WIN
you'd better addWIN
to the "conditional compilation symbols" (in Visual Studio: ProjectProperties/Build) to get it set every time you compile that project. :)Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
Hi, First of all, I'm so sorry for asking such a n00b question, but in VC++ 8 I could found the preprocessors directives easily but with C# for VS2008 I have no idea where they are... What directive should I test to be sure the application was compile in Windows?
#if WIN
? Thanks, Dirso
The .NET side of Visual Studio does not define any of the "standard" C++ defines. It does have support for the
#if
preprocessor directive, but you will need to define your own symbols. The only ones that are pre-defined for you, as far as I can remember, are DEBUG and TRACE.
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
The .NET side of Visual Studio does not define any of the "standard" C++ defines. It does have support for the
#if
preprocessor directive, but you will need to define your own symbols. The only ones that are pre-defined for you, as far as I can remember, are DEBUG and TRACE.
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
This is from the C# Language Specification[^] The following pre-processing directives are available: • #define and #undef, which are used to define and undefine, respectively, conditional compilation symbols (§2.5.3). • #if, #elif, #else, and #endif, which are used to conditionally skip sections of source code (§2.5.4). • #line, which is used to control line numbers emitted for errors and warnings (§2.5.7). • #error and #warning, which are used to issue errors and warnings, respectively (§2.5.5). • #region and #endregion, which are used to explicitly mark sections of source code (§2.5.6). • #pragma, which is used to specify optional contextual information to the compiler (§2.5.8). Enjoy, Robert C. Cartaino
-
This is from the C# Language Specification[^] The following pre-processing directives are available: • #define and #undef, which are used to define and undefine, respectively, conditional compilation symbols (§2.5.3). • #if, #elif, #else, and #endif, which are used to conditionally skip sections of source code (§2.5.4). • #line, which is used to control line numbers emitted for errors and warnings (§2.5.7). • #error and #warning, which are used to issue errors and warnings, respectively (§2.5.5). • #region and #endregion, which are used to explicitly mark sections of source code (§2.5.6). • #pragma, which is used to specify optional contextual information to the compiler (§2.5.8). Enjoy, Robert C. Cartaino
Did you mean this to go to me or the original poster? Good reference on what directives are available, but the question was really about what compilation symbols are defined by default. The OP wanted to know how to write the equivalent of
#if WIN
in C# (assuming that "WIN" is a predefined conditional symbol in C++), to which the answer is still "there isn't".Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
Did you mean this to go to me or the original poster? Good reference on what directives are available, but the question was really about what compilation symbols are defined by default. The OP wanted to know how to write the equivalent of
#if WIN
in C# (assuming that "WIN" is a predefined conditional symbol in C++), to which the answer is still "there isn't".Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
Scott Dorman wrote:
Did you mean this to go to me or the original poster?
No, not really to the original poster nor directly to you either. I just thought it a good place to inject further information into the thread. I was just following up on the part of your answer that said, "...It does have support for the #if preprocessor directive." I was just adding to the conversation.
-
Scott Dorman wrote:
Did you mean this to go to me or the original poster?
No, not really to the original poster nor directly to you either. I just thought it a good place to inject further information into the thread. I was just following up on the part of your answer that said, "...It does have support for the #if preprocessor directive." I was just adding to the conversation.
Robert.C.Cartaino wrote:
No, not really to the original poster nor directly to you either. I just thought it a good place to inject further information into the thread. I was just following up on the part of your answer that said, "...It does have support for the #if preprocessor directive." I was just adding to the conversation.
No worries, just wasn't sure if this was a "general" post or not. The list of available directives is good, as many people probably don't know about them.
Scott Dorman
Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
-
Hi Dirso, I'm not an expert in preprocessor directives (so, this post could be useless), but, thinking that .Net was made only for Windows (MONO was developed after) i've seen one that might help you: #if !MONO #endif I think that this was made on purpose... If you want yo know if you are in MONO, ask for it... Windows is assume. HTH Dirso, Pablo.-
-
Hi Dirso, I'm not an expert in preprocessor directives (so, this post could be useless), but, thinking that .Net was made only for Windows (MONO was developed after) i've seen one that might help you: #if !MONO #endif I think that this was made on purpose... If you want yo know if you are in MONO, ask for it... Windows is assume. HTH Dirso, Pablo.-
-
I guess you're right! I'll investigate a little more about MONO and see how it goes. Thanks, Dirso
Dirso, i was right, but incomplete... After doing some research i´ve found: .- How to define/use preprocessor directives http://www.c-sharpcorner.com/UploadFile/vgupta/PreprocessorDirectivesCS11162005235503PM/PreprocessorDirectivesCS.aspx[^] .- How to detect if you are running in MONO http://www.mono-project.com/FAQ:_Technical#How_can_I_detect_if_am_running_in_Mono.3F[^] .- Conditional Compilation http://bytes.com/forum/thread214072.html[^] HTH, Pablo.-
-
Dirso, i was right, but incomplete... After doing some research i´ve found: .- How to define/use preprocessor directives http://www.c-sharpcorner.com/UploadFile/vgupta/PreprocessorDirectivesCS11162005235503PM/PreprocessorDirectivesCS.aspx[^] .- How to detect if you are running in MONO http://www.mono-project.com/FAQ:_Technical#How_can_I_detect_if_am_running_in_Mono.3F[^] .- Conditional Compilation http://bytes.com/forum/thread214072.html[^] HTH, Pablo.-