Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Preprocessor Directives

Preprocessor Directives

Scheduled Pinned Locked Moved C#
questioncsharpc++
13 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Gareth H

    Dirso, Well since .NET only runs in a Windows environment, why would you need to check this...

    Regards, Gareth. (FKA gareth111)

    D Offline
    D Offline
    Dirso
    wrote on last edited by
    #3

    Hi, Mono runs under linux as well, right? Thanks, Dirso

    P 1 Reply Last reply
    0
    • D Dirso

      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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #4

      Hi, AFAIK there are no predefined symbols in C#. So if your code includes a #if WIN you'd better add WIN 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|


      1 Reply Last reply
      0
      • D Dirso

        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

        S Offline
        S Offline
        Scott Dorman
        wrote on last edited by
        #5

        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


        [Forum Guidelines][Articles][Blog]

        R 1 Reply Last reply
        0
        • S Scott Dorman

          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


          [Forum Guidelines][Articles][Blog]

          R Offline
          R Offline
          Robert C Cartaino
          wrote on last edited by
          #6

          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

          S 1 Reply Last reply
          0
          • R 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

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #7

            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


            [Forum Guidelines][Articles][Blog]

            R 1 Reply Last reply
            0
            • S Scott Dorman

              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


              [Forum Guidelines][Articles][Blog]

              R Offline
              R Offline
              Robert C Cartaino
              wrote on last edited by
              #8

              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.

              S 1 Reply Last reply
              0
              • R Robert C Cartaino

                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.

                S Offline
                S Offline
                Scott Dorman
                wrote on last edited by
                #9

                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


                [Forum Guidelines][Articles][Blog]

                1 Reply Last reply
                0
                • D Dirso

                  Hi, Mono runs under linux as well, right? Thanks, Dirso

                  P Offline
                  P Offline
                  Pablo Cervio
                  wrote on last edited by
                  #10

                  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.-

                  D 1 Reply Last reply
                  0
                  • P Pablo Cervio

                    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.-

                    D Offline
                    D Offline
                    Dirso
                    wrote on last edited by
                    #11

                    I guess you're right! I'll investigate a little more about MONO and see how it goes. Thanks, Dirso

                    P 1 Reply Last reply
                    0
                    • D Dirso

                      I guess you're right! I'll investigate a little more about MONO and see how it goes. Thanks, Dirso

                      P Offline
                      P Offline
                      Pablo Cervio
                      wrote on last edited by
                      #12

                      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.-

                      D 1 Reply Last reply
                      0
                      • P Pablo Cervio

                        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.-

                        D Offline
                        D Offline
                        Dirso
                        wrote on last edited by
                        #13

                        That was wonderful!!! Thank you so much!!! Dirso

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups