#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif
What does ## mean in C? Is that a placeholder or function?
Macro in C programming is known as the piece of code defined with the help of the #define directive. Macros in C are very useful at multiple places to replace the piece of code with a single value of the macro. Macros have multiple types and there are some predefined macros as well.
The double-number-sign or token-pasting operator (##), which is sometimes called the merging or combining operator, is used in both object-like and function-like macros. It permits separate tokens to be joined into a single token, and therefore, can't be the first or last token in the macro definition.
and as part of C++0x. Function-like macro definition: An identifier followed by a parameter list in parentheses and the replacement tokens. The parameters are imbedded in the replacement code. White space cannot separate the identifier (which is the name of the macro) and the left parenthesis of the parameter list.
The #define creates a macro, which is the association of an identifier or parameterized identifier with a token string. After the macro is defined, the compiler can substitute the token string for each occurrence of the identifier in the source file.
It is called the token pasting operator, it concatenates tokens so that 123313 ## LL
becomes 123313LL
during the preprocessing.
There is also a stringification operator #
, which converts #name
into "name"
.
No, ##
is not a placeholder for a function, it is a token pasting operator. It is valid only inside preprocessor macros (with or without parameters). It produces a concatenation of its left and right sides.
For example, if you pass INT64_C
a value of 123
INT64_C(123)
the result produced by the preprocessor would be equivalent to writing
123LL
The idea behind these macros is to make signed and unsigned constants stand out in the code a little more: a value that looks like INT64_C(123)
may be a little more readable than the equivalent 123LL
. It is definitely a big improvement over its other equivalent 123ll
, which looks like a completely different number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With