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#
tutorialannouncement
6 Posts 3 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.
  • D Offline
    D Offline
    Deresen
    wrote on last edited by
    #1

    Hello everyone, I've got a project and I am making a version 2 of this project. Though still version 1 must be active and used. So I'm using preprocessor directives to assign the extra parts for the program for version 2. But in this case I have to place a #define VERSION_2 in every file where I want to make a difference between version 1 and version 2. I would like to know if it is possible to put a #define in one file and use it in another file. For example:

    //file test.cs

    //#define VERSION_1
    #define VERSION_2

    namespace Prog.test
    {
    class test
    {
    #if VERSION_1
    doThat();
    #elif VERSION_2
    doAnother();
    #endif
    }
    }

    //file chair.cs

    namepace Prog.chair
    {
    class chair
    {
    #if VERSION_1 //does not work, because not defined
    setHeight();
    #elif VERSION_2 //does not work, because not defined
    setWidth();
    #endif
    }
    }

    L realJSOPR 2 Replies Last reply
    0
    • D Deresen

      Hello everyone, I've got a project and I am making a version 2 of this project. Though still version 1 must be active and used. So I'm using preprocessor directives to assign the extra parts for the program for version 2. But in this case I have to place a #define VERSION_2 in every file where I want to make a difference between version 1 and version 2. I would like to know if it is possible to put a #define in one file and use it in another file. For example:

      //file test.cs

      //#define VERSION_1
      #define VERSION_2

      namespace Prog.test
      {
      class test
      {
      #if VERSION_1
      doThat();
      #elif VERSION_2
      doAnother();
      #endif
      }
      }

      //file chair.cs

      namepace Prog.chair
      {
      class chair
      {
      #if VERSION_1 //does not work, because not defined
      setHeight();
      #elif VERSION_2 //does not work, because not defined
      setWidth();
      #endif
      }
      }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You can define them in the project properties:

      Project -> (Name) Properties -> Build -> Conditional compilation symbols

      regards

      D 1 Reply Last reply
      0
      • L Lost User

        You can define them in the project properties:

        Project -> (Name) Properties -> Build -> Conditional compilation symbols

        regards

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

        Thank you very much! That's all I needed :-D

        1 Reply Last reply
        0
        • D Deresen

          Hello everyone, I've got a project and I am making a version 2 of this project. Though still version 1 must be active and used. So I'm using preprocessor directives to assign the extra parts for the program for version 2. But in this case I have to place a #define VERSION_2 in every file where I want to make a difference between version 1 and version 2. I would like to know if it is possible to put a #define in one file and use it in another file. For example:

          //file test.cs

          //#define VERSION_1
          #define VERSION_2

          namespace Prog.test
          {
          class test
          {
          #if VERSION_1
          doThat();
          #elif VERSION_2
          doAnother();
          #endif
          }
          }

          //file chair.cs

          namepace Prog.chair
          {
          class chair
          {
          #if VERSION_1 //does not work, because not defined
          setHeight();
          #elif VERSION_2 //does not work, because not defined
          setWidth();
          #endif
          }
          }

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          I would think the best way to accomplish backwards compatibility is to derive a new class from the original, and then the calling assembly can use whichever version it wants. No need for compiler directives at all.

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          L 1 Reply Last reply
          0
          • realJSOPR realJSOP

            I would think the best way to accomplish backwards compatibility is to derive a new class from the original, and then the calling assembly can use whichever version it wants. No need for compiler directives at all.

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Why not using branches on a version control system (like SVN)? Sure, this makes things a bit complicated but should keep the code pretty clean. regards

            realJSOPR 1 Reply Last reply
            0
            • L Lost User

              Why not using branches on a version control system (like SVN)? Sure, this makes things a bit complicated but should keep the code pretty clean. regards

              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #6
              1. He's talking about making an assembly compatible between versions. Source control is completely out of context. 1) Just because you *can* make it more complex, doesn't mean you should.

              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

              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