Multiple preprocessor directives on one line in C++

前端 未结 3 1834
盖世英雄少女心
盖世英雄少女心 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:54

    Preprocessor directives are somewhat different than language statements, which are terminated by ; and use whitespace to delimit tokens. In the case of the preprocessor, the directive is terminated by a newline so it's impossible to do what you're attempting using the C++ language itself.

    One way you could kind of simulate this is to put your desired lines into a separate header file and then #include it where you want. The separate header still has to have each directive on one line, but the point where you include it is just a single line, effectively doing what you asked.

    Another way to accomplish something like that is to have a pre-C++ file that you use an external process to process into a C++ source file prior to compiling with your C++ compiler. This is probably rather more trouble than it's worth.

提交回复
热议问题