Newsgroups: comp.std.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: Does ANSI insist this is legal?
Message-ID: <1990Feb28.180914.27504@utzoo.uucp>
Organization: U of Toronto Zoology
References: <25EB8750.5286@paris.ics.uci.edu>
Date: Wed, 28 Feb 90 18:09:14 GMT

In article <25EB8750.5286@paris.ics.uci.edu> rfg@paris.ics.uci.edu (Ronald Guilmette) writes:
>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; }

Holy Scriptures, Oct 88 draft, verse 3.3.4:

	A pointer may be converted to an integral type.  The size of
	integer required and the result are implementation-defined.
	If the space provided is not long enough, the behavior is
	undefined.

Your program falls under the jurisdiction of that last sentence, since
it is vanishingly unlikely that a pointer will fit in a char and not too
likely nowadays that it will fit in a short.  So the compiler can remove
all your files, send rude mail to your boss, and dump core if it wants.
-- 
"The N in NFS stands for Not, |     Henry Spencer at U of Toronto Zoology
or Need, or perhaps Nightmare"| uunet!attcan!utzoo!henry henry@zoo.toronto.edu
