[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

About Conditional Inclusion

Huangsyx

4/17/2011 12:18:00 AM

#include <stdio.h>

int main(void)
{
int a = 1;

#if 1 == a
puts("Success");
#else
puts("Failure");
#endif

return 0;
}

I've Compile this code in Visual C++ 6.0 and MingW.
It' Ok, but puts"Failure".
Why?
Alsoly, I've Compier this code in Turbo C 2.0. The TC(Turbo C)2.0 report an Error."Constant expression required in function main".

What the definination of "constant of expression"?

I am a beginner.:)
1 Answer

Ben Pfaff

4/17/2011 12:24:00 AM

0

Huangsyx <huangsyx@gmail.com> writes:

> int a = 1;
>
> #if 1 == a
> puts("Success");
> #else
> puts("Failure");
> #endif

This does not do what you think it does. Variables are not
visible in preprocessor expressions. In preprocessor
expressions, undefined names are silently replaced by 0. So "#if
1 == a" is equivalent to "#if 1 == 0".

> I've Compile this code in Visual C++ 6.0 and MingW.
> It' Ok, but puts"Failure".
> Why?

This should be clear.

> Alsoly, I've Compier this code in Turbo C 2.0. The TC(Turbo
> C)2.0 report an Error."Constant expression required in function
> main".

Turbo C 2.0 was released late in 1988. I doubt that it is fully
ANSI C compliant. Use some other compiler.
--
Ben Pfaff
http://be...