a question about preprocessor

X

xuatla

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
 
D

Denis Remezov

xuatla said:
[...]

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top