Check for compiler switch in code

This is a discussion on Check for compiler switch in code within the C++ Programming forums, part of the General Programming Boards category; I've written a Unit testing framework for an embedded system that reports the location of tests using __FILE__ and __LINE__. ...

  1. #1
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597

    Check for compiler switch in code

    I've written a Unit testing framework for an embedded system that reports the location of tests using __FILE__ and __LINE__. This is all well and good, except I also want to run the code on Visual Studio.

    Now microsoft, in their infinite wisdom, change the meaning of __FILE__ depending on other compiler switches. For example if /Zi (note case of 'i') is defined __FILE__ is the relative path (to the project), but if /ZI is defined __FILE__ is the absolute path!!! (these, btw, defined the debugger database format. Imagining how that relates __FILE__ fills with horror)

    The path needs to be absolute so our reporting tools can load those files. so I'd like to force users to specify /FC (an undocumented switch that creates absolute paths ). I tried:
    Code:
    #if defined(WIN32) && !defined(FC)
    #error Please add /FC to your compiler options
    #endif
    but unfortunately that doesn't work. Anyone know a way that does? and yes, I've STFW...
    Last edited by ChaosEngine; 05-10-2007 at 05:58 PM.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I don't think a command line switch is the same as a #define.
    Code:
    #if defined(WIN32) && !defined(FC)
    #error Please add /FC to your compiler options
    #endif
    FWIW:
    http://predef.sourceforge.net/preos.html#sec22
    http://predef.sourceforge.net/precomp.html#sec32
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Dave_Sinkula View Post
    I don't think a command line switch is the same as a #define.
    I know. But some compiler switches cause #defines (for example _MT is defined for mulit-threaded builds), I was just hoping this might be the case here. No biggie.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,803
    http://msdn2.microsoft.com/en-us/lib...2s(VS.80).aspx
    Doesn't look like it defines anything. But seems there is a way in managed code to do it.
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you check if my code and descriptions are correct?
    By Cyberman86 in forum C Programming
    Replies: 1
    Last Post: 02-06-2009, 12:22 PM
  2. Not working in linux...
    By mramazing in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2009, 01:18 AM
  3. allegro issues
    By mramazing in forum C++ Programming
    Replies: 1
    Last Post: 01-07-2009, 10:56 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 03:28 AM
  5. can someone check this code
    By xpflyer2002 in forum C Programming
    Replies: 5
    Last Post: 09-16-2002, 03:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21