Why both clang and gcc only give a warning when there is a space after backslash if C standard says that whitespace is forbidden?

后端 未结 4 1455
青春惊慌失措
青春惊慌失措 2020-12-02 02:15

When compiling the following snippet, both gcc and clang only issue a warning. Notice space after \\ next to int:

#include 

        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 02:39

    A warning is generated when this happens. Don't write code that depends on this behavior; it is provided because trailing whitespace is significant (almost) nowhere else, and we get much better error recovery if we treat them as line continuations. Especially don't write code that depends on being able to put a comment after a line continuation, that is an accident of the implementation and will change in the future.

    If you want to disable extensions, like the other answer says, enable warnings and use -pedantic-errors. Otherwise, feel free to use whatever features the compiler gives you as long as you understand the implications and what benefits they provide. If you want C99 mode, make sure to add -std=c99 to the command line.

提交回复
热议问题