What is the difference between using #ifdef and #if defined? I've seen comments in code like "Here we had to use the horrible ifdef", but no comments on if defined in the same code. So what's the difference?
What is the difference between using #ifdef and #if defined? I've seen comments in code like "Here we had to use the horrible ifdef", but no comments on if defined in the same code. So what's the difference?
Some compilers won't read #if defined, but I am pretty sure all of them support #ifdef
i've never seen an 'if defined' directive... i'd presume that there is a condition 'defined', and it's tested as an if in an 'if'... seeing as how that's how it appears off hand... this is interesting, can someone explain? thanks...
hasafraggin shizigishin oppashigger...
> What is the difference between using #ifdef and #if defined?
#ifdef FOO
and
#if defined(FOO)
are the same,
but to do several things at once, you can use defined, like
#if defined(FOO) || defined(BAR)
/* some stuff */
#endif
With only #ifdef, it gets really messy
#ifdef FOO
/* some stuff */
#endif
#ifdef BAR
#ifndef FOO /* in case FOO has already done it */
/* some stuff */
#endif
#endif
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
If you're deaf than get a hearing aid, and if you can't find one than ignore what you don't understand, just keep going.Difference between ifdef and if defined?
Huh? Shouldn't you understand what you're doing? That doesn't sound like a good advice..
>If you're deaf than get a hearing aid, and if you can't find one than ignore what you don't understand, just keep going.
niice... and wow that's pretty interesting... never would have figured... too bad i'm on hiatus tho... dang...
hasafraggin shizigishin oppashigger...