What does the following C macro do?

#ifndef INT64_C #define INT64_C(c) (c ## LL) #define UINT64_C(c) (c ## ULL) #endif 

What does ## in C mean? Is it a placeholder or function?

+6
source share
4 answers

It is called a token handler , it combines tokens so that 123313 ## LL becomes 123313LL during preprocessing.

There is also a # operator that converts #name to "name" .

+10
source

No, ## not a placeholder for a function, it is a token labeling operator. It is valid only inside preprocessor macros (with or without parameters). It creates a concatenation of the left and right sides.

For example, if you pass INT64_C value 123

 INT64_C(123) 

the result generated by the preprocessor will be equivalent to writing

 123LL 

The idea behind these macros is that constants, signed and unsigned, stand out a bit more in the code: a value that looks like INT64_C(123) may be a little more readable than the equivalent of 123LL . This is certainly a big improvement over the other 123LL equivalent, which looks like a completely different number.

+4
source

## means the union of two tokens.

So (c ## LL) will be pre-processed before cLL .

But note that this was done at the preprocessing stage so that strcat did not like strcat .

 int i = 3; INT64_C(i); 

will generate iLL instead of 3LL .

+4
source

As already mentioned, ## inserts two tokens together.

 #define INT64_C(c) (c ## LL) 

So, INT64_C(123) becomes (123LL) after macro expansion.

These macros exist, so you can use int64_t constants with the int64_t . On most 64-bit systems, a macro will be defined as such:

 #define INT64_C(c) (c ## L) 

This is due to the fact that on most 64-bit systems int64_t is long , so the constant should be 123L . On most 32-bit systems and on Windows, int64_t has a long long , so the constant should be 123LL .

+2
source

Source: https://habr.com/ru/post/945971/


All Articles