[vim/vim] C syntax highlighting bug with uncommented #include (#5705)

28 views
Skip to first unread message

Bogdan Barbu

unread,
Feb 27, 2020, 3:53:24 PM2/27/20
to vim/vim, Subscribed

Try the following:
/* */ #include <stdio.h>
or
/*
*/ #include <stdio.h>

The directive #include will not be highlighted.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Christian Brabandt

unread,
Feb 28, 2020, 1:21:20 AM2/28/20
to vim/vim, Subscribed
Is that actually valid syntax?

> Am 27.02.2020 um 21:53 schrieb Bogdan Barbu <notifi...@github.com>:
>
> 

Mike Williams

unread,
Feb 28, 2020, 6:53:09 AM2/28/20
to vim_dev
On Friday, 28 February 2020 06:21:20 UTC, Christian Brabandt wrote:
Is that actually valid syntax?

It is valid syntax. According to the standard all comments are replaced with spaces before executing pre-processor directives like #include. This means any directive can appear after a comment. Not a typical coding convention but perfectly valid.

Bogdan Barbu

unread,
Feb 28, 2020, 8:58:53 AM2/28/20
to vim/vim, Subscribed

Yes. According to section 5.1.1.2 of the C standard, comments are replaced by a space character before #include preprocessing directives are interpreted. Also, tested with GCC, just in case.

Bogdan Barbu

unread,
Feb 28, 2020, 11:50:36 AM2/28/20
to vim/vim, Subscribed

What you probably had in mind was something along the lines of:

#define EMPTY
EMPTY #include <stdio.h>

where #include is indeed not a preprocessing directive because EMPTY will not have been replaced at the end of the 4th translation phase, as defined in the specification. This already works as expected.

Bram Moolenaar

unread,
Feb 28, 2020, 4:25:11 PM2/28/20
to vim/vim, Subscribed

Not all valid syntax can be recognized. The highlighting is pattern based, it is not a full parser.
This construct is unusual enough that we don't need to support it.
I would discourage writing it like that anyway, better put the comment above the #include.

Bram Moolenaar

unread,
Feb 28, 2020, 4:25:15 PM2/28/20
to vim/vim, Subscribed

Closed #5705.

Reply all
Reply to author
Forward
0 new messages