Concatenation Operator ##

This page was translated by a robot.

The double ##is a macro operator that causes a concatenation of the two operands left and right without additional space. This turns two symbols into one, which is why this macro operator is also known as a symbol operator and in English as a tokenizer . In the following example, the float variant of the transferred math function is called automatically:






PI = 3.000000
#include <stdio.h>
#include <math.h>
#define MATH(func, args) func ## f (args)

int main(){
  printf("PI = %f\n", MATH(floor, 3.14));
  return 0;
}

Details

The above line is translated as follows:

printf("PI = %f\n", floorf (3.14));

If one of the operands on the left or right is a macro, this will NOT be resolved. The only exception to this rule is the __VA_ARGS__macro, which is evaluated correctly. The following lines illustrate this:



floorSUFFIX (3.14);


floorf (3.14);
#define SUFFIX f
#define MATH(func, args) func ## SUFFIX (args)
MATH(floor, 3.14);

#define MATH(func, args, ...) func ## __VA_ARGS__ (args)
MATH(floor, 3.14, f);

Any preprocessor token can be used as an operand, as long as the combination results in a valid preprocessor token. Attempting to use this macro operator outside of a #definedirective in code will result in the compiler reporting an error.

A special meaning of the double hash character ##is found in GCC for variadic macros.