Checking for whether compiler supports C99 or C++0x

Discussion in 'C++' started by er ci, Jul 24, 2010.

  1. er ci

    er ci Guest

    I think I've seen

    #ifdef __C99__

    before, but is there something similar for C++0x?

    Thanks.
     
    er ci, Jul 24, 2010
    #1
    1. Advertising

  2. er ci

    Bo Persson Guest

    er ci wrote:
    > I think I've seen
    >
    > #ifdef __C99__
    >
    > before, but is there something similar for C++0x?
    >
    > Thanks.


    You the symbol __cplusplus which is defined to be 199711L for
    compilers following the 1998 standard, supposedly approved in november
    1997.

    This symbol will get a new value for C++0x. We just don't know yet
    what date it will be - perhaps 201111L ?


    Bo Persson
     
    Bo Persson, Jul 24, 2010
    #2
    1. Advertising

  3. er ci

    Öö Tiib Guest

    On 24 juuli, 19:31, er ci <> wrote:
    > I think I've seen
    >
    > #ifdef __C99__
    >
    > before, but is there something similar for C++0x?


    No compiler supports fully next standard. If you want to write
    portable code then avoid all that C++0x for 3-4 years *after* (if it
    ever) becomes standard. You will have lot of portability-related fun
    without it, that is guaranteed.
     
    Öö Tiib, Jul 24, 2010
    #3
  4. Bo Persson <> wrote:
    > You the symbol __cplusplus which is defined to be 199711L for
    > compilers following the 1998 standard, supposedly approved in november
    > 1997.
    >
    > This symbol will get a new value for C++0x. We just don't know yet
    > what date it will be - perhaps 201111L ?


    You could always do an #if (__cplusplus > 199711)
     
    Juha Nieminen, Jul 27, 2010
    #4
  5. er ci

    er Guest

    Actually, what would be ideal would be check whether the compiler flag
    -std=c++0x has been set. Can compiler flags be "caught" by a pp macro?
     
    er, Aug 17, 2010
    #5
  6. er ci

    SG Guest

    On 17 Aug., 10:48, er <> wrote:
    > Actually, what would be ideal would be check whether the compiler flag
    > -std=c++0x has been set. Can compiler flags be "caught" by a pp macro?


    In this case (GCC invoked with -std=c++0): Yes. See its documentation
    (look for a section called "predefined macros" or something along
    these lines).

    Cheers!
    SG
     
    SG, Aug 17, 2010
    #6
  7. er ci

    er Guest


    > The built-in macro __cplusplus is the standard way of checking the C++



    How exactly, please, as I'm unable to verify this? See below

    Under GCC 4.4, with -std=c++0x, under OSX 10.6.4,

    #include <iostream>

    void f(T&&){} // to be sure that c++0x is enabled,

    int main(){

    std::cout << "cpp : " << __cplusplus << std::endl; // outputs 1

    #if __cplusplus > 199711L
    const enable = true;
    #else
    const enable = false;
    #endif

    assert( enable ); // fails

    return 0;
    }
     
    er, Aug 18, 2010
    #7
  8. er ci

    er Guest

    Correction:

    template<typename T>
    > void f(T&&){} // to be sure that c++0x is enabled,
     
    er, Aug 18, 2010
    #8
  9. er ci

    er Guest

    Of course, it should be

    const bool enable

    >    const enable = true;
    >    #else
    >    const enable = false;
    >    #endif


    (Since the code is run from a virtual machine, I have to copy it
    manually.)
     
    er, Aug 18, 2010
    #9
  10. er ci

    SG Guest

    On 18 Aug., 14:48, er wrote:
    >
    > Under GCC 4.4, with -std=c++0x, under OSX 10.6.4,
    >
    >    std::cout << "cpp : " << __cplusplus << std::endl; // outputs 1
    >
    >    #if __cplusplus > 199711L
    >    const bool enable = true;
    >    #else
    >    const bool enable = false;
    >    #endif
    >
    >    assert( enable ); // fails


    You have been told already that there IS NOT YET an official value the
    __cplusplus macro expands to for the next C++ revision. The next
    revision is NOT YET DONE.

    As for why GCC uses 1 instead of 199711 or how to detect the
    experimental C++0x mode, you will find the answers in your compiler's
    manual.
    http://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html

    Cheers!
    SG
     
    SG, Aug 18, 2010
    #10
  11. er ci

    er Guest

    >
    > You have been told already that there IS NOT YET an official value the


    Yes, but I'm not testing for an exact value, only a half-range. It was
    my understanding from previous comments that this would suffice.
    Thanks for the links.

    Would this be the relevant section for GCC?

    3.7.1 Standard Predefined Macros

    __cplusplus
    This macro is defined when the C++ compiler is in use. You can use
    __cplusplus to test whether a header is compiled by a C compiler or a C
    ++ compiler. This macro is similar to __STDC_VERSION__, in that it
    expands to a version number. A fully conforming implementation of the
    1998 C++ standard will define this macro to 199711L. The GNU C++
    compiler is not yet fully conforming, so it uses 1 instead. It is
    hoped to complete the implementation of standard C++ in the near
    future.

    So I guess GCC is out for checking C++0x

    3.7.3 System-specific Predefined Macros

    When the -ansi option, or any -std option that requests strict
    conformance, is given to the compiler, all the system-specific
    predefined macros outside the reserved namespace are suppressed.

    What does reserved namespace mean, here?
     
    er, Aug 18, 2010
    #11
  12. er ci

    SG Guest

    On 18 Aug., 15:30, er wrote:
    >
    > So I guess GCC is out for checking C++0x


    In addition to Pete's comment: You gotta try much harder. For example,
    look for "C++0x" on that page I linked to. RTFM!

    > What does reserved namespace mean, here?


    The answer to that is on the same page you quoted the paragraph from!
    RTFM!

    Cheers!
    SG
     
    SG, Aug 18, 2010
    #12
  13. er ci

    er Guest

    On Aug 18, 10:19 am, SG <> wrote:
    > On 18 Aug., 15:30, er wrote:
    >
    >
    >
    > > So I guess GCC is out for checking C++0x

    >
    > In addition to Pete's comment: You gotta try much harder. For example,


    Sorry, I wasn't trying too hard anymore, just sharing what caught my
    eye as a courtesy to whoever stumbles upon this pb, bec the effort of
    finding portable across platforms/compilers solution is not going to
    be worth it. For now I'll just manually set a macro to switch between
    two implementations, where relevant, one for C03 and the other that
    exploits C++0x features.

    > look for "C++0x" on that page I linked to. RTFM!


    You mean this?

    __GXX_EXPERIMENTAL_CXX0X__
    This macro is defined when compiling a C++ source file with the
    option -std=c++0x or -std=gnu++0x. It indicates that some features
    likely to be included in C++0x are available. Note that these features
    are experimental, and may change or be removed in future versions of
    GCC.

    Yes, I took note the comments that C++0x is not a finalized product.
    The reason I pursue it to be able to switch between two
    implementations (see above) as some people already request C++0x
    feature, notwithstanding its incompleteness.

    >
    > > What does reserved namespace mean, here?

    >
    > The answer to that is on the same page you quoted the paragraph from!
    > RTFM!


    OK, got it.

    >
    > Cheers!
    > SG
     
    er, Aug 18, 2010
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peng Yu
    Replies:
    2
    Views:
    737
    Default User
    Sep 29, 2004
  2. Ashabul Yeameen
    Replies:
    1
    Views:
    356
    Mike Wahler
    Sep 16, 2003
  3. Ashabul Yeameen
    Replies:
    2
    Views:
    450
    Ashabul Yeameen
    Sep 17, 2003
  4. Replies:
    3
    Views:
    3,755
    Chris Torek
    Feb 20, 2006
  5. Replies:
    3
    Views:
    625
    Keith Thompson
    Mar 31, 2007
Loading...

Share This Page