This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: preprocessing directive with no new-line character
- From: Vincent Lefevre <vincent+gcc at vinc17 dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 17 Jul 2017 16:15:17 +0200
- Subject: Re: preprocessing directive with no new-line character
- Authentication-results: sourceware.org; auth=none
- References: <20170717131958.GA23989@zira.vinc17.org> <CA+7wUswGQyztN70aiHRp1RARa4-erV6cYN2Ys=gD0st6x-Z4PA@mail.gmail.com>
On 2017-07-17 16:09:42 +0200, Mathieu Malaterre wrote:
> On Mon, Jul 17, 2017 at 3:19 PM, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> > According to the C standard (either C99 or C11), a preprocessing
> > directive ends with a new-line character: "The last token in the
> > sequence is the first new-line character that follows the first
> > token in the sequence."
> >
> > But GCC accepts the following program with -std=c99 -pedantic:
> >
> > int main (void)
> > {
> > return 0;
> > }
> > #define FOO
> >
> > where there is no new-line character after "FOO".
> >
> > Is there any reason?
>
> Do you have 0x0A at the end of your text file ?
No:
zira:~> hd tst.c
00000000 69 6e 74 20 6d 61 69 6e 20 28 76 6f 69 64 29 0a |int main (void).|
00000010 7b 0a 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a |{. return 0;.}.|
00000020 23 64 65 66 69 6e 65 20 46 4f 4f |#define FOO|
0000002b
And BTW, Clang behaves as expected:
zira:~> clang-4.0 -std=c99 -pedantic tst.c -o tst
tst.c:5:12: warning: no newline at end of file [-Wnewline-eof]
#define FOO
^
1 warning generated.
So, I think that's a bug in GCC. Do you agree?
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)