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

Conditional Compilation

Scheduled Pinned Locked Moved C#
helpvisual-studiocomperformance
4 Posts 2 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.
  • H Offline
    H Offline
    HosamAly
    wrote on last edited by
    #1

    Hello, I have a piece of code that should be subject to conditional compilation. I'm trying to compare the use of a conditional directive vs. using an if-condition over a const variable. The second approach looks safer from compilation perspective, but the first one has its advantages (e.g. save memory by not declaring unused variables). I'd appreciate your help on best practices regarding this issue...

    Many thanks to all helpful guys here in CP! I really appreciate your help. :rose: Know me better

    P 1 Reply Last reply
    0
    • H HosamAly

      Hello, I have a piece of code that should be subject to conditional compilation. I'm trying to compare the use of a conditional directive vs. using an if-condition over a const variable. The second approach looks safer from compilation perspective, but the first one has its advantages (e.g. save memory by not declaring unused variables). I'd appreciate your help on best practices regarding this issue...

      Many thanks to all helpful guys here in CP! I really appreciate your help. :rose: Know me better

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Another alternative is to make it configurable. It depends on just what it is you're trying to do.

      H 1 Reply Last reply
      0
      • P PIEBALDconsult

        Another alternative is to make it configurable. It depends on just what it is you're trying to do.

        H Offline
        H Offline
        HosamAly
        wrote on last edited by
        #3

        Yes, but I don't need that level at the moment. Additionally, making it configurable doesn't allow the compiler to do certain optimizations. For example, checking a const variable which is statically known to be either true or false gives the compiler an opportunity to optimize the check away, and keep only the relevant code (with unreachable code detected warning).

        Many thanks to all helpful guys here in CP! I really appreciate your help. :rose: Know me better

        P 1 Reply Last reply
        0
        • H HosamAly

          Yes, but I don't need that level at the moment. Additionally, making it configurable doesn't allow the compiler to do certain optimizations. For example, checking a const variable which is statically known to be either true or false gives the compiler an opportunity to optimize the check away, and keep only the relevant code (with unreachable code detected warning).

          Many thanks to all helpful guys here in CP! I really appreciate your help. :rose: Know me better

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Then use conditional compilation.

          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