I want to extensively use the ##-operator and enum magic to handle a huge bunch of similar access-operations, error handling and data flow.

If applying the `##` and `#` preprocessor operators results in an invalid pp-token, the behavior is undefined in C.

The order of preprocessor operation in general is not defined (\*) in C90 (see [The token pasting operator](http://www.complete-concrete-concise.com/programming/c/preprocessor-the-token-pasting-operator)). Now in some cases it happens (said so in different sources, including the MISRA Committee, and the referenced page) that the order of multiple ##/#-Operators influences the occurrence of undefined behavior. But I have a really hard time to understand the examples of these sources and pin down the common rule.

So my questions are:

1. What are the rules for valid pp-tokens?
2. Are there difference between the different C and C++ Standards?
3. My current problem: Is the following legal with all 2 operator orders?(\*\*)

```
#define test(A) test_## A ## _THING
int test(0001) = 2;

```

Comments:

(\*) I don't use "is undefined" because this has nothing to do with undefined behavior yet IMHO, but rather unspecified behavior. More than one ## or # operator being applied do not in general render the program to be erroneous. There is obviously an order — we just can't predict which — so the order is unspecified.

(\*\*) This is no actual application for the numbering. But the pattern is equivalent.