|
Packit |
b40e2e |
/* u_1_22.c: Undefined behaviors on generating invalid pp-token by ##
|
|
Packit |
b40e2e |
operator. */
|
|
Packit |
b40e2e |
|
|
Packit |
b40e2e |
#include <stdio.h>
|
|
Packit |
b40e2e |
#define str( a) # a
|
|
Packit |
b40e2e |
|
|
Packit |
b40e2e |
main( void)
|
|
Packit |
b40e2e |
{
|
|
Packit |
b40e2e |
|
|
Packit |
b40e2e |
/* u.1.22: Result of ## operator is not a valid pp-token. */
|
|
Packit |
b40e2e |
#define NUM( dig, exp) dig ## E+ ## exp
|
|
Packit |
b40e2e |
/*
|
|
Packit |
b40e2e |
* "E+" is a sequence of two pp-tokens "E" and "+", not a single pp-token.
|
|
Packit |
b40e2e |
* The first ## concatenates the last pp-token of first argument with "E",
|
|
Packit |
b40e2e |
* and the second ## concatenates "+" with the first pp-token of the second
|
|
Packit |
b40e2e |
* argument.
|
|
Packit |
b40e2e |
* While "12E" (one of the sequence generated by the token concatenation)
|
|
Packit |
b40e2e |
* is a valid pp-token, "+34" (the another sequence) is not a valid pp-token
|
|
Packit |
b40e2e |
* and causes an undefined behavior.
|
|
Packit |
b40e2e |
*/
|
|
Packit |
b40e2e |
printf( "%e\n", NUM( 12, 34));
|
|
Packit |
b40e2e |
|
|
Packit |
b40e2e |
return 0;
|
|
Packit |
b40e2e |
}
|
|
Packit |
b40e2e |
|