🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #198

GNU C preprocessor and the ANSI C spec

#198
From: Quentin Barnes
Date: Fri, 10 Apr 1992 20:30
46 lines
2415 bytes
(This is my third attempt at posting this article with the first
 two were trached by news so hopefully there are no duplicates.)

In working with the GNU C preprocessor, I have come across several
behaviors which appear to deviate from the ANSI C spec (X3.159-1989).
I am hoping to have someone knowledgeable in the spec will confirm or
deny my suspicions. 

1) In chapter 3.8 which discusses C preprocessing, no mention is
   made of what should occur when a '#' directive is encountered
   which does not fall under the preprocessor syntax.  I would
   assume that unrecognized '#' directives would be an error
   in the preprocessing stage.  For example, if the input file
   has '#foo', what is the correct ANSI C behavior?

   The GNU C preprocessor silently passes unrecognized directives to
   the compiler and expects the compiler to declare the error.

2) For line control (3.8.4), the preprocessor must use '#line'.
   An alternate syntax '# digit-sequence' is not legal under ANSI C.

   The GNU C preprocessor will generate '#line' style if compiled
   with OUTPUT_LINE_COMMANDS otherwise it generates the alternate
   syntax.  To be closer to ANSI C compliance, the preprocessor must
   be built with this compile time option defined.  Correct?

3) The ANSI C spec in 3.8.4 states that '#line' directives must be
   of the format:
	# line digit-sequence new-line
   or
	# line digit-sequence "s-char-sequence" new-line

   In 3.8.4 around line 20, the spec does state that the form:
	# line pp-tokens new-line
   is allowed, but after processing the tokens, the syntax must
   fall into one of the first two forms.

   The GNU C preprocessor will generate '#line' directives in the
   format which adds a digit "1" or "2" if entering or exiting an
   included file.  For example:
	# line 34 "myfile.h" 1

   This seems in violation of the ANSI C spec.
-- 
Quentin Barnes
qbarnes@urbana.mcd.mot.com | ..!uiucuxc!udc!qbarnes
Technical Details
Message-ID: <1992Apr10.203007.18865@urbana.mcd.mot.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!asuvax!mcdphx!udc!qbarnes

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!asuvax!mcdphx!udc!qbarnes
From: qbarnes@urbana.mcd.mot.com (Quentin Barnes)
Newsgroups: comp.std.c
Subject: GNU C preprocessor and the ANSI C spec
Message-ID: <1992Apr10.203007.18865@urbana.mcd.mot.com>
Date: 10 Apr 92 20:30:07 GMT
Sender: news@urbana.mcd.mot.com (News)
Organization: Motorola Computer Group, Urbana Design Center
Lines: 46
Nntp-Posting-Host: neptune.urbana.mcd.mot.com