This one bit me today

Bob Goudreau goudreau at dg-rtp.dg.com
Tue Oct 24 06:59:25 AEST 1989


In article <273 at bbxsda.UUCP> scott at bbxsda.UUCP (Scott Amspoker) writes:
>Bob Goudreau writes:
>
>>My point was that any such compilers (or compiler-instantiations created
>>by invoking the same program with different switches) may *claim* to be
>>C compilers, but claiming isn't enough.  Such compilers are *broken*, at
>>least as C compilers.
>
>I don't get it.  Are you saying that a C compiler that allows the option
>of nested comments is *broken*?  I believe Turbo C has a nested comments
>option.

Yes, please re-read my reply.  Any such language translator is *broken*
if it purports to be a translator of the C language, for the simple
reason that such a program violates translator behavior that is mandated
by all the important definitions of the C language (K&R, ANSI).

I'm not saying that this fact necessarily means such programs are
useless and should be discarded immediately; I'm just saying that it
is wrong to say that they are C compilers.

Also note that I spoke of "compiler-instantiations created by invoking
the same program with different switches".  By that I mean that each
invocation of a compiler is, in effect, a completely different program
if the command line switches cause different behavior.  So, while
"turbocc -nest-comments" (or whatever) may indeed fail as a C compiler,
"turbocc" without that switch may be valid.

>I agree that a compiler that insists on nesting comments is
>probably non-conforming (I say "probably" because I can't recite the
>actual ANSI text at this moment).

Replace the "probably" with a "definitely" (see section 3.1.9 of the
pANS).  And note that this is not an ANSI invention;  comments have
never nested in the C language.  More to the point, the pre-ANSI de
facto standard (K&R) did not even allow implementations the latitude
to *choose* their behavior in this regard.  K&R 1 states unambiguously
at the beginning of Appendix A: "Comments do not nest."

>But what's wrong with command line options that allow various
>enhancements?

Nothing, in general.  But I have three particular bones to pick with
respect to this "enhancement":

1)  It is not upward compatible with C.  It is possible to take valid,
	portable C source code and compile it in this manner and get
	a program that runs differently than expected.

2)  It encourages use of this non-feature by programmers who might
	think that they are writing portable C code.  I know, they
	should know better, but why add this pitfall at all?

3)  It is not even necessary.  How is it any better than using
	"#if 0 .... #endif" as a mechanism for "commenting-out" code
	blocks?

-------------------------
Bob Goudreau				+1 919 248 6231
Data General Corporation		...!mcnc!rti!xyzzy!goudreau
62 Alexander Drive			goudreau at dg-rtp.dg.com
Research Triangle Park, NC  27709, USA



More information about the Comp.lang.c mailing list