21

Out of curiousity, I'm reading the Zend Engine API code and encountered quite a number of ## in their #define's. For example, at /usr/lib/php5/Zend/zend_API.h:

#define ZEND_FN(name) zif_##name
#define ZEND_MN(name) zim_##name

What does the ## (double hash) symbols mean in these two lines?

mihai
  • 4,592
  • 3
  • 29
  • 42
Seh Hui Leong
  • 1,112
  • 1
  • 8
  • 19

3 Answers3

31

The ## concatenates what's before the ## with what's after it. So in your example doing ZEND_FN(foo) would result in zif_foo

Ronny Vindenes
  • 2,361
  • 1
  • 18
  • 15
6

Echo RvV's answer.

Be aware that when concatenating literal strings you may find some inconsistencies between pre-processors/compilers. Some will require the ##

#define STR_CAT(s1, s2)   s1 ## s2

as in

const char s[] = STR_CAT("concat", "enation")

whereas other will baulk at it, and instead just require that the two literals will be joined by the compiler (as opposed to the pre-processor), so will require

#define STR_CAT(s1, s2)   s1 s2

HTH

dcw
  • 3,481
  • 2
  • 22
  • 30
3

http://www.cppreference.com/wiki/preprocessor/sharp

vartec
  • 131,205
  • 36
  • 218
  • 244