[comp.lang.c] Should #include <foo.h>; compile?

drack@titan.tsd.arlut.utexas.edu (Dave Rackley) (02/19/91)

In article <7605@jhunix.HCF.JHU.EDU> barrett@jhunix.HCF.JHU.EDU (Dan Barrett) writes:

>   Should this program compile?
>
>       #include <stdio.h>;
>       main() {}

>   I have one compiler that complains about the semicolon after the ">", and
>   one that doesn't.  Which is right?  My suspicion is that the program is
>   legal, because a semicolon by itself is an empty statement.  The error
>   message produced by the picky compiler is:
>
>       test.c:1: #include expects "fname" or <fname>

>   Both compilers accept:
>
>       #include <stdio.h>
>       ;
>       main() {}
>

Preprocessor directives are bounded by *line boundaries* not semi-colons.
Per K&R, 2d edition, page 228:  "...any character not otherwise defined is 
taken as a token."  Therefore, it is my opinion that your first example should
not compile (precompile).

--

  DISCLAIMER:  I, hereby, disclaim any disclaimer except this disclaimer.  

+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
| David Rackley                 | Now comes the really weird part...You know  |
| Applied Research Laboratories | the part where I know how to tap dance, but |
| The University of Texas       | only while wearing golf shoes...            |
| Austin, TX.  78758            |        ...Ponderous, man, really ponderous! |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+

gwyn@smoke.brl.mil (Doug Gwyn) (02/20/91)

In article <7605@jhunix.HCF.JHU.EDU> barrett@jhunix.HCF.JHU.EDU (Dan Barrett) writes:
>Should this program compile?
>	#include <stdio.h>;
>	main() {}

Since it violates at least one syntax rule in the C standard, a
diagnostic is required from a conforming implementation.

The failure of main() to return a value results in undefined behavior,
by the way.