Does ANSI insist this is legal?

Henry Spencer henry at utzoo.uucp
Fri Mar 2 04:41:47 AEST 1990


In article <25EC428B.18849 at paris.ics.uci.edu> rfg at ics.uci.edu (Ronald Guilmette) writes:
>>	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.
>
>I agree that any attempt to use a space which is not long enough (to hold
>the pointer value initializer) can (allowably, under the standard) cause you
>to lose all your files, can cause your boss to receive rude mail, and can
>cause a core dump, but the $64,000 question is "When may these catastrophies
>occur?  At run-time or at compile-time?  Either?  Both?"

"Undefined" really means "undefined".  Your text editor might send rude
mail to your boss when you type in that code (if your text editor is part
of your C implementation); the final report printed by your program might
contain the words "it's all lies, they're juggling the books".  Or anything
in between.  Or any combination of the above.

>Right now, GCC accepts the above program without complaint (but I'm sure
>that is the values of `s' or `c' were used, that run-time strangeness
>would ensue).  The question is whether or not a standard conforming compiler
>is *allowed* to "reject" the above code at compile time.

Yes.  Good compilers, in fact, will try to reject such things at compile
time rather than leaving run-time disasters lurking in wait for you.
(Alas, it is seldom possible to detect them at compile time in the general
case.)
-- 
MSDOS, abbrev:  Maybe SomeDay |     Henry Spencer at U of Toronto Zoology
an Operating System.          | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.std.c mailing list