Directives in comments

David H Close compata at cup.portal.com
Thu Dec 21 13:19:44 AEST 1989


Any computer language is really defined by its implementations, not by
the formal specifications.  If most or every implementation consistently
violates the specification in some specific way, the de facto specification
is changed to conform to the implementation.  I have recently encountered
an instance of C syntax which is unacceptable to my compiler but which
appears should be correct by the specifications.  I'd appreciate any comments
from the net as to whether this represents a compiler bug or a de facto
change to the specifications.

In the SCO Xenix C Language Reference (SCO-514-210-014, 6-21-87), page 8-1,
it states:  "Directives can appear anywhere in a source file, but they apply
only to the remainder of the source file in which they appear."  This appears
to be consistent with K&R (1978), which states on page 207, "These lines
[beginning with a #] have syntax independent of the rest of the language;
they may appear anywhere and have effect which lasts (independent of scope)
until the end of the source program file."

The following program fragment appears to conform to the rules stated.

	/*
	 *            Program heading
	 #define hdr "Program name"
	 *            end of heading
	 */
	main () { printf(hdr); }

However, the SCO compiler produces the following error message.

	t.c(6) : error 65: 'hdr' : undefined

K&R's assertion that directives "have syntax independent of the rest of
the language" would appear to me to allow the example.  However, this
appears to me to be so fundamental to C that, if it were truly a bug,
it couldn't have survived until now.

If you post a reply, please email me a copy to insure I don't miss it.

Dave Close, Compata, Arlington, Texas
compata at cup.portal.com



More information about the Comp.lang.c mailing list