#if defined

D

Dave

Is the construct #if defined MACRO_NAME part of standard C++?

If so, how does it differ from #ifdef?

Thanks!
 
M

Martin Magnusson

Dave said:
Is the construct #if defined MACRO_NAME part of standard C++?

If so, how does it differ from #ifdef?

From what I could gather from a fairly quick web search, "#ifdef XX"
and "#if defined (XX)" are exactly equivalent.

/ martin
 
P

Pete Becker

Dave said:
Is the construct #if defined MACRO_NAME part of standard C++?

If so, how does it differ from #ifdef?

Yes, it's part of standard C++ as well as standard C. To see the
difference, try writing something that depends on having more than one
macro defined.
 
J

jeffc

Dave said:
Is the construct #if defined MACRO_NAME part of standard C++?

If so, how does it differ from #ifdef?

Yes, you can use either I think. You can choose
#ifdef
#if defined
#ifndef
#if !defined
I see no mention of "defined" in Stroustrup's C++ Programming Language 3rd
ed. It's a bit more sophisticated in terms of logic, since you can write
things like
#if defined (macro1) || !defined (macro2) || defined (macro3)
 
U

Unforgiven

Dave said:
Is the construct #if defined MACRO_NAME part of standard C++?

As far as I know, yes.
If so, how does it differ from #ifdef?

It doesn't really differ much. #ifdef is shorthand for #if defined.

I tend to use the latter when I have to combine more than one #if, like
this:
#if defined(_MSC_VER) && _MSC_VER < 1300
 

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

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,825
Members
47,371
Latest member
Brkaa

Latest Threads

Top