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. The Lounge
  3. Where do you put your Visual Studio preprocessor directives?

Where do you put your Visual Studio preprocessor directives?

Scheduled Pinned Locked Moved The Lounge
visual-studiohelpquestioncsharpc++
7 Posts 4 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.
  • C Offline
    C Offline
    charlieg
    wrote on last edited by
    #1

    Context: I've been busy trying to get a very stable and old solution to build in VS2008. It's a mess of code and 40+ projects accumulated over the years - mostly MFC stuff - this means stdafx.h. Over the years, multiple developers (myself included) tended to slap preprocessor definitions in stdafx.h and I suspect other places; it's always fine until someone gets hurt. In this case, sometimes my solution will build and sometimes not. I started the general trend to put the definitions in the IDE properties window. I'm thinking this was a mistake, as sometimes the definitions propagate and sometimes not. Part of the problem of specifying directives using the IDE is that Microsoft's IDEs do rude stuff to project files. I see this all the time comparing SVN commits in an attempt to determine what has changed. The IDE has no issue with re-ordering things. So, what is your preference or practice in managing your preprocessor directives?

    Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

    G Mircea NeacsuM C honey the codewitchH 5 Replies Last reply
    0
    • C charlieg

      Context: I've been busy trying to get a very stable and old solution to build in VS2008. It's a mess of code and 40+ projects accumulated over the years - mostly MFC stuff - this means stdafx.h. Over the years, multiple developers (myself included) tended to slap preprocessor definitions in stdafx.h and I suspect other places; it's always fine until someone gets hurt. In this case, sometimes my solution will build and sometimes not. I started the general trend to put the definitions in the IDE properties window. I'm thinking this was a mistake, as sometimes the definitions propagate and sometimes not. Part of the problem of specifying directives using the IDE is that Microsoft's IDEs do rude stuff to project files. I see this all the time comparing SVN commits in an attempt to determine what has changed. The IDE has no issue with re-ordering things. So, what is your preference or practice in managing your preprocessor directives?

      Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      We have one symbol that may be defined in our project files: ENGINEERING. We have build configurations that define the symbol and can be used in source code for engineering-specific builds. These are used for experiments or prototyping logic before a production implementation. We avoid defining symbols in project files otherwise, since it's easy to lose a definition when changing configurations. Our stdafx.h files #define conditional compilation values like WINVER and #include 'fixed' header files for the C++ runtime, MFC, and so on. These are files where using precompiled headers improve compile times. It will also #include a file that defines the application version and build number, software title, copyright and trademark statements, and so on. This ensures that every executable file, DLL or EXE, gets the same information in the version resource. Conditional compilation symbols and manifest constants tend to be defined centrally. For a class, that's in the header file for the class. If the element is built from several classes in separate source files, they're in a separate header for the element. If a value is used throughout the project, it will typically be in stdafx.h.

      Software Zen: delete this;

      1 Reply Last reply
      0
      • C charlieg

        Context: I've been busy trying to get a very stable and old solution to build in VS2008. It's a mess of code and 40+ projects accumulated over the years - mostly MFC stuff - this means stdafx.h. Over the years, multiple developers (myself included) tended to slap preprocessor definitions in stdafx.h and I suspect other places; it's always fine until someone gets hurt. In this case, sometimes my solution will build and sometimes not. I started the general trend to put the definitions in the IDE properties window. I'm thinking this was a mistake, as sometimes the definitions propagate and sometimes not. Part of the problem of specifying directives using the IDE is that Microsoft's IDEs do rude stuff to project files. I see this all the time comparing SVN commits in an attempt to determine what has changed. The IDE has no issue with re-ordering things. So, what is your preference or practice in managing your preprocessor directives?

        Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

        Mircea NeacsuM Offline
        Mircea NeacsuM Offline
        Mircea Neacsu
        wrote on last edited by
        #3

        Never in the project file. I've been bitten in my behind too many times by symbols that were or were not defined in different project/configurations that I'll never do that again. If the project has more than a few global defines, they go to a file called defs.h.

        Mircea

        1 Reply Last reply
        0
        • C charlieg

          Context: I've been busy trying to get a very stable and old solution to build in VS2008. It's a mess of code and 40+ projects accumulated over the years - mostly MFC stuff - this means stdafx.h. Over the years, multiple developers (myself included) tended to slap preprocessor definitions in stdafx.h and I suspect other places; it's always fine until someone gets hurt. In this case, sometimes my solution will build and sometimes not. I started the general trend to put the definitions in the IDE properties window. I'm thinking this was a mistake, as sometimes the definitions propagate and sometimes not. Part of the problem of specifying directives using the IDE is that Microsoft's IDEs do rude stuff to project files. I see this all the time comparing SVN commits in an attempt to determine what has changed. The IDE has no issue with re-ordering things. So, what is your preference or practice in managing your preprocessor directives?

          Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

          C Offline
          C Offline
          charlieg
          wrote on last edited by
          #4

          Okay, so I had another thought to dig into this deeper. I agree and understand what has been said, especially the part about avoiding stdafx.h changes. However, there are times when changes must happen, especially when building for CE and WEC7. The part that bothers me is that in my solution I have 60+ stdafx.h files - one for every project. Obviously, for a given build they should all be the same. Because of this problem, it sort of makes sense to push some settings to a prop file or something (I've been reading). Under no circumstances should application defines be in the project settings unless target related, and even that I might be able to work around.

          Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

          1 Reply Last reply
          0
          • C charlieg

            Context: I've been busy trying to get a very stable and old solution to build in VS2008. It's a mess of code and 40+ projects accumulated over the years - mostly MFC stuff - this means stdafx.h. Over the years, multiple developers (myself included) tended to slap preprocessor definitions in stdafx.h and I suspect other places; it's always fine until someone gets hurt. In this case, sometimes my solution will build and sometimes not. I started the general trend to put the definitions in the IDE properties window. I'm thinking this was a mistake, as sometimes the definitions propagate and sometimes not. Part of the problem of specifying directives using the IDE is that Microsoft's IDEs do rude stuff to project files. I see this all the time comparing SVN commits in an attempt to determine what has changed. The IDE has no issue with re-ordering things. So, what is your preference or practice in managing your preprocessor directives?

            Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

            honey the codewitchH Offline
            honey the codewitchH Offline
            honey the codewitch
            wrote on last edited by
            #5

            I've had no end of issues with Microsoft and C++, whether it was their compiler being weird or Visual Studio causing me headaches. In the end I moved over to VS Code and I build my own "project files" (which are not project files but rather CMake build scripts but they do what I need) Sorry I can't be more help. I eventually gave up on the approach you took with your project.

            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

            C 1 Reply Last reply
            0
            • honey the codewitchH honey the codewitch

              I've had no end of issues with Microsoft and C++, whether it was their compiler being weird or Visual Studio causing me headaches. In the end I moved over to VS Code and I build my own "project files" (which are not project files but rather CMake build scripts but they do what I need) Sorry I can't be more help. I eventually gave up on the approach you took with your project.

              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

              C Offline
              C Offline
              charlieg
              wrote on last edited by
              #6

              understand. back in my unix days, makefiles were the way to go.

              Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

              1 Reply Last reply
              0
              • C charlieg

                Context: I've been busy trying to get a very stable and old solution to build in VS2008. It's a mess of code and 40+ projects accumulated over the years - mostly MFC stuff - this means stdafx.h. Over the years, multiple developers (myself included) tended to slap preprocessor definitions in stdafx.h and I suspect other places; it's always fine until someone gets hurt. In this case, sometimes my solution will build and sometimes not. I started the general trend to put the definitions in the IDE properties window. I'm thinking this was a mistake, as sometimes the definitions propagate and sometimes not. Part of the problem of specifying directives using the IDE is that Microsoft's IDEs do rude stuff to project files. I see this all the time comparing SVN commits in an attempt to determine what has changed. The IDE has no issue with re-ordering things. So, what is your preference or practice in managing your preprocessor directives?

                Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

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

                oh it gets better. So one part of my solution has a project with 15 subprojects. If I build each subproject separately, no errors. Build the project as a whole? Nope, issues out the kazoo. I feel I'm getting closer though.

                Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

                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