Does ANSI insist this is legal?

Walter Murray walter at hpclwjm.HP.COM
Fri Mar 2 03:43:26 AEST 1990


Ronald Guilmette asks:

> Must a strictly conforming ANSI C implementation be able to generate an
> executable program from the following?


>	int main ();
>	short s = (short) &main;
>	char c = (char) &main;
>	int main () { return 0; }

No.  Setting aside the question of whether a pointer can fit in a char
or a short, this code violates Section 3.4:  "Cast operators in an
arithmetic constant expression shall only convert arithmetic types
to arithmetic types, except as part of an operand to the sizeof
operator."

Walter Murray
----------



More information about the Comp.std.c mailing list