Simple question: if unary operators have near the highest priority, then why the order of evaluation of # and ## operators is unspecified? Relevant to both C and C++.

C11 (6.10.3.2 The # operator):

The order of evaluation of # and ## operators is unspecified.

C++, N4713 (19.3.2 The # operator):

The order of evaluation of # and ## operators is unspecified.

1

There are 1 best solutions below

0
On BEST ANSWER

Chapter 19 in the C++17 standard is titled "Preprocessing directives". It explains how the preprocessor works.

As the name suggests, the preprocessor is processed before the rest of C or C++'s rules. So operator precedence does not apply; these are not operators resulting in expressions. The preprocessing "operators" # and ## within a #define macro definition are not parts of the C or C++ language. They're parts of the C/C++ preprocessor; they are not "unary operators" as defined in section 8.3 of the C++17 standard.

During preprocessor evaluation and macro manipulation, there are no expressions. There is only a sequence of tokens, which the macro system defines a couple of transformation operators for (namely, # and ##). The grammar of C and C++ are not yet involved in the process.

So the question is moot: their evaluation order is unspecified because they have no relationship to regular C or C++ operators, and the standard says that their order is unspecified.