Directives in comments

Jim Davis davis at hplabsz.HPL.HP.COM
Fri Dec 29 13:11:45 AEST 1989


David H Close <compata at cup.portal.com> wrote:
dhc>	[...text deleted...] This appears to be consistent with K&R (1978), ...
dhc>	The following program fragment appears to conform to the rules stated.
dhc>		/*
dhc>		 *            Program heading
dhc>		 #define hdr "Program name"
dhc>		 *            end of heading
dhc>		 */
dhc>		main () { printf(hdr); }

dhc>	K&R's assertion that directives "have syntax independent of the
dhc>	rest of the language" would appear to me to allow the example.

Reino de Boer <reino at cs.eur.nl> quite correctly replied:
rdb>	In K&R Second Edition pp. 228--229, A12. Preprocessing:
rdb>	 3. The program is split into tokens separated by white-space
rdb>	 characters; comments are replaced by a single space. Then
rdb>	   	     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^(only then)
rdb>	 preprocessing directives are obeyed, and macros (...) are expanded.

rdb>	Hope this explains -- Reino

I would add one more nit.  The example presented does not have
"lines beginning with a #".  The "#define" was indented.  The
'#' symbol must not (at least in the compilers I am familliar with)
be preceeded by whitespace.
-- 
Jim Davis (James W. Davis)      Palo Alto, CA        (415)857-4036
davis at hplabs.hp.com             {any_of_the_biggies}!hplabs!davis



More information about the Comp.lang.c mailing list