Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the # for when formatting using %s

I came across this example of an assertion and was wondering what the # is for:

#define ASSERT( x ) if ( !( x ) ) { \
    int *p = NULL; \
    DBGPRINTF("Assert failed: [%s]\r\n Halting.", #x); \
    *p=1; \
  } 
like image 951
Fructose Avatar asked Mar 18 '11 15:03

Fructose


People also ask

What is the in grammar?

The definite article (the) is used before a noun to indicate that the identity of the noun is known to the reader. The indefinite article (a, an) is used before a noun that is general or when its identity is not known. There are certain situations in which a noun takes no article.

What kind of word is the?

The word the is considered a definite article because it defines the meaning of a noun as one particular thing. It's an article that gives a noun a definite meaning: a definite article. Generally, definite articles are used to identify nouns that the audience already knows about.

Where is the is used?

The is used to describe a specific noun, whereas a/an is used to describe a more general noun. For this reason, the is also referred to as a definite article, and a/an is referred to as an indefinite article. The definite article, the, is used before both singular and plural nouns when the noun is specific.

Why does English use the?

The word the is very important to native speakers of English because it is used to divide the world we process through language into two categories: old information and new information. It helps us to divide the world into things which we agree are known, or important, and things which we feel aren't.


2 Answers

It is the "stringize" preprocessing operator.

It takes the tokens passed as the argument to the macro parameter x and turns them into a string literal.

#define ASSERT(x) #x

ASSERT(a b c d)
// is replaced by
"a b c d"
like image 145
James McNellis Avatar answered Oct 26 '22 23:10

James McNellis


#x is the stringification directive

#define Stringify(x) #x

means Stringify(abc) will be substituted with "abc"

as in

#define initVarWithItsOwnName(x) const char* p = #x

int main()
{
   initVarWithItsOwnName(Var);
   std::cout << Var; //will print Var
}
like image 39
Armen Tsirunyan Avatar answered Oct 27 '22 00:10

Armen Tsirunyan