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. Other Discussions
  3. The Weird and The Wonderful
  4. What's the best way to do conditional compile?

What's the best way to do conditional compile?

Scheduled Pinned Locked Moved The Weird and The Wonderful
linuxhelpquestionlounge
9 Posts 8 Posters 2 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.
  • C Offline
    C Offline
    crewchill
    wrote on last edited by
    #1

    I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?

    P K S M E 7 Replies Last reply
    0
    • C crewchill

      I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      crewchill wrote:

      I've seen #if else nested 8 level deep, with structures whose definition has more #if in it

      Well, that would certainly be a programming horror. Please, feel free to post it up so that we can all gasp in dismay and horror at the sheer beastly inhumanity of it.

      Deja View - the feeling that you've seen this post before.

      1 Reply Last reply
      0
      • C crewchill

        I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        Then you have for every platform own code, which will do the same. One change and you work in every file. I hate nested #if but this seems not to be better. X| I try to be prepared for this via structuring classes for use with or without API and MFC.:~

        Greetings from Germany

        1 Reply Last reply
        0
        • C crewchill

          I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?

          S Offline
          S Offline
          Saksida Bojan
          wrote on last edited by
          #4

          I Have put on hold certan project, i am using nested #if. I am using for a feature and permision to be build or not. I chose this aprouach, so it woudnt be hacked. Also an option to hardcode a connection string, or specificy manul. Another reason i have chosen is because i wanted to make open source, so if someone woud modify, then they coud get direct database accsess. But i have put it on hold, Because i am doing asp.net version, And when it will be finished, i woud have appropriate schema. The way it is currently progresing, i think i won't need nested #if statments, Instead if i woud put script betwen application and server.

          1 Reply Last reply
          0
          • C crewchill

            I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?

            M Offline
            M Offline
            Mike Dimmick
            wrote on last edited by
            #5

            I maintain a thin client which was originally designed for Symbol Series 3000 DOS-based handheld computers. Over time it's been ported to desktop Windows (for testing), Palm (for Symbol's relatively short-lived Palm devices with integrated scanners), other DOS-based handhelds and a variety of Windows CE and Pocket PC-based devices. The device-specific stuff tended to be implemented originally with #ifdefs but where possible I've replaced that with separate implementations, where the code needed to be completely different. In some places, I've replaced platform defines with feature defines, and added a configuration header which sets the feature defines up appropriately per-platform (unfortunately Microsoft C 6.0 . Finally, to try to keep the number of builds manageable, in some places I've used dynamic loading on CE using LoadLibrary/GetProcAddress to detect whether a feature is supported. This can happen if you're trying to use some manufacturer-specific APIs, for example we try to determine whether a Symbol MC3000 has full waveform-audio support or simply a beeper. The waveform-audio version supports the beeper API but with a significant amount of latency, so we use our own waveform-generator where possible (and of course it's necessary on the non-Symbol devices anyway).


            DoEvents: Generating unexpected recursion since 1991

            1 Reply Last reply
            0
            • C crewchill

              I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?

              E Offline
              E Offline
              earl the dead cat
              wrote on last edited by
              #6

              can't you just replace a nested if with case statement in many cases?

              C 1 Reply Last reply
              0
              • E earl the dead cat

                can't you just replace a nested if with case statement in many cases?

                C Offline
                C Offline
                crewchill
                wrote on last edited by
                #7

                It's not nested if... it's nested #if. And the reason they have to do #if, is that in certain platform the function or even the structure protected inside the #if is not available (not compiled).

                1 Reply Last reply
                0
                • C crewchill

                  I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?

                  P Offline
                  P Offline
                  Philip Laureano
                  wrote on last edited by
                  #8

                  An example of a conditional compile would be:

                  // If you uncomment the following line I will beat you to death with a rusty, blunt instrument
                  // File.Delete("*.*");

                  :)

                  1 Reply Last reply
                  0
                  • C crewchill

                    I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?

                    N Offline
                    N Offline
                    NimitySSJ
                    wrote on last edited by
                    #9

                    The use of good cross-platform libraries and API's helps reduce or prevent much preprocessor ugliness. If you do it like one person said, with a project/program for each platform, you can simplify that by encapsulating core functionality whenever possible for reuse with many platforms. I often do what I can to separate program logic from GUI code, so that I could port the software to many platforms, while leaving the main logic untouched. (Of course, wxWidgets or Qt with ANSI C++ often means I hardly change a thing, but most people aren't using such libraries...) -Nick P.

                    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