Newsgroups: comp.std.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Does ANSI insist this is legal? Message-ID: <1990Mar1.174147.29502@utzoo.uucp> Organization: U of Toronto Zoology References: <25EB8750.5286@paris.ics.uci.edu> <1990Feb28.180914.27504@utzoo.uucp> <25EC428B.18849@paris.ics.uci.edu> Date: Thu, 1 Mar 90 17:41:47 GMT In article <25EC428B.18849@paris.ics.uci.edu> rfg@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@zoo.toronto.edu