Multiple preprocessor directives on one line in C++

前端 未结 3 1837
盖世英雄少女心
盖世英雄少女心 2021-02-07 16:26

A hypothetical question: Is it possible to have a C++ program, which includes preprocessor directives, entirely on one line?

Such a line would look like this:

         


        
3条回答
  •  后悔当初
    2021-02-07 16:40

    A preprocessing directive must be terminated by a newline, so this is actually a single preprocessing directive that defines an object-like macro, named foo, that expands to the following token sequence:

    # ifdef foo # define bar # endif
    

    Any later use of the name foo in the source (until it is #undefed) will expand to this, but after the macro is expanded, the resulting tokens are not evaluated as a preprocessing directive.

    This is not compiler-specific; this behavior is defined by the C and C++ standards.

提交回复
热议问题