Pelles C forum

C language => Expert questions => Topic started by: andi.martin on December 17, 2008, 07:26:36 PM

Title: directive #if and operator sizeof
Post by: andi.martin on December 17, 2008, 07:26:36 PM
Hi,

AFAIK the sizeof operator returns a constant expression (integer type).
So why
#if sizeof(char)==1
emits a compiler error..?

Regards,
Andreas Martin
Title: Re: directive #if and operator sizeof
Post by: JohnF on December 18, 2008, 08:38:41 AM
Hi,

AFAIK the sizeof operator returns a constant expression (integer type).
So why
#if sizeof(char)==1
emits a compiler error..?

Regards,
Andreas Martin

I would imagine that using it in a pre-processing context is disallowed.

John
Title: Re: directive #if and operator sizeof
Post by: pgoh on December 18, 2008, 08:06:51 PM
John is correct. sizeof is evaluated at compile time, while the preprocessor is evaluated before compilation.