Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > a question about preprocessor

Reply
Thread Tools

a question about preprocessor

 
 
xuatla
Guest
Posts: n/a
 
      07-10-2004
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
 
Reply With Quote
 
 
 
 
Denis Remezov
Guest
Posts: n/a
 
      07-10-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines snnn C++ 6 03-14-2005 04:09 PM
preprocessor, token concatenation, no valid preprocessor token Cronus C++ 1 07-14-2004 11:10 PM
preprocessor implementation GURU question Dan W. C++ 9 12-04-2003 02:24 AM
preprocessor question Neil Zanella C Programming 4 11-06-2003 03:30 PM
Preprocessor's question C Programming 1 09-12-2003 05:32 PM



Advertisments