What does “#define STR(a) #a” do?

In the first definition, #a means to print the macro argument as a string. This will turn, e.g. STR(foo) into "foo", but it won’t do macro-expansion on its arguments.

The second definition doesn’t add anything to the first, but by passing its argument to another macro, it forces full macro expansion of its argument. So XSTR(expr) creates a string of expr with all macros fully expanded.

Leave a Comment