a question about preprocessor

Discussion in 'C++' started by xuatla, Jul 10, 2004.

  1. xuatla

    xuatla Guest

    I tried the following code and complied in g++

    #include <iostream>
    using namespace std;

    int main()
    {
    #ifdef __cplusplus
    cout << "c++ program" << endl;
    #endif

    #ifdef __STDC__
    cout << "c program" << endl;
    #endif

    return 0;
    }

    the output is
    c++ program
    c program

    So both __cplusplus & __STDC__ are defined. But from C++ Primer I read
    that only one of them will be defined in a program. What's wrong with my
    code/result?

    Thanks.

    X
    xuatla, Jul 10, 2004
    #1
    1. Advertising

  2. xuatla wrote:
    >

    [...]
    >
    > So both __cplusplus & __STDC__ are defined. But from C++ Primer I read
    > that only one of them will be defined in a program. What's wrong with my
    > code/result?
    >


    Everything is right. For a C++ program, __cplusplus is required to be
    defined. __STDC__ is required for C programs. For C++, __STDC__
    is still allowed, but not required.

    Denis
    Denis Remezov, Jul 10, 2004
    #2
    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. Dan W.
    Replies:
    9
    Views:
    324
    Paul Mensonides
    Dec 4, 2003
  2. Cronus
    Replies:
    1
    Views:
    643
    Paul Mensonides
    Jul 15, 2004
  3. ³á³á³á³á

    Preprocessor's question

    ³á³á³á³á, Sep 12, 2003, in forum: C Programming
    Replies:
    1
    Views:
    323
    Martin Ambuhl
    Sep 12, 2003
  4. Neil Zanella

    preprocessor question

    Neil Zanella, Nov 6, 2003, in forum: C Programming
    Replies:
    4
    Views:
    314
    Eric Sosman
    Nov 6, 2003
  5. Charlie Zender

    C-preprocessor macro question

    Charlie Zender, Dec 24, 2003, in forum: C Programming
    Replies:
    3
    Views:
    446
    Richard Bos
    Dec 24, 2003
Loading...

Share This Page