-1

From The C Programming Language, by KRC

Given the definition

#define tempfile(dir)    #dir "%s" 

the macro call tempfile(/usr/tmp) yields

"/usr/tmp" "%s" 

which will subsequently be catenated into a single string.

Which rule does the concatenation of the two strings at the end follow?

Is the rule for macros in preprocessing, or for strings in C in compilation ?

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
Tim
  • 1
  • 141
  • 372
  • 590

1 Answers1

3

This happens according to one of the phases of the translation.

Quoting C11, chapter §5.1.1.2/p1.4 and p1.6, (according to the order)

Preprocessing directives are executed, macro invocations are expanded, and _Pragma unary operator expressions are executed. [...]

and

Adjacent string literal tokens are concatenated.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • I would add that preprocessing is over at the end of phase 4 and concatenation happens in phase 6. Also it's list item 6 on paragraph 1, not paragraph 6. – user694733 Aug 16 '16 at 13:08