Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pound sign in #define function parameters [duplicate]

Tags:

c++

What does the pound sign indicate in this line of code?

#define CONDITION(x)    if(!(x)){ HandleError(#x,__FUNCTION__,__LINE__);return false;}

This is how it is being called:

CONDITION(foo != false);
like image 307
marsh Avatar asked Dec 09 '22 04:12

marsh


1 Answers

A single # before a macro parameter converts it to a string literal.

#define STRINGIFY(x) #x
STRINGIFY(hello)   // expands to "hello"

In your example, the string would be "foo != false", so that the error message shows the code that was being tested.

A double ## between two tokens within a macro combines them into a single token

#define GLOM(x,y) x ## y
GLOM(hello, World) // expands to helloWorld
like image 109
Mike Seymour Avatar answered Dec 19 '22 14:12

Mike Seymour