Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do two adjacent pound signs mean in a C macro?

Tags:

I'm taking a look at an application that defines a large set of constant arrays. What really confuses me is the use of two pound signs next to each other in a macro. For example:

#define r0(p,q,r,s) 0x##p##q##r##s 

What do those two pound signs mean?

like image 813
sj755 Avatar asked Jan 30 '12 05:01

sj755


People also ask

What does ## mean in macro in C?

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.

What does the '#' symbol do in macro expansion?

The number-sign or "stringizing" operator (#) converts macro parameters to string literals without expanding the parameter definition. It's used only with macros that take arguments.

Can a macro call itself in C?

You can't have recursive macros in C or C++.

Can you define a macro twice C?

If you define a macro twice like that, the compiler should at least give you warning, if not an error. It is an error. §6.10.


1 Answers

## provides a way to concatenate actual arguments during macro expansion.

like image 82
Alok Save Avatar answered Sep 27 '22 19:09

Alok Save