0

Possible Duplicate:
C preprocessor and concatenation
C preprocessor # and ## operators

While searching through some C code of an OS that I develop with (on an embedded project,) I found the following defines statement:

#define concatn(s1, s2) s1 ## s2

I've never seen the "##" operator and after a bit of serious googling, I can't find any reference to it. What's going on here?

I've searched through the OS source, and I can't find any reference to the string "##" being defined as some other form of C operator. Is this standard C, or is this possibly/probably a feature of the compiler?

Community
  • 1
  • 1
RLH
  • 15,230
  • 22
  • 98
  • 182
  • 3
    concatenate in the preprocessor – im so confused Oct 09 '12 at 19:51
  • ["## Operator C" -> I'm Feeling Lucky](http://publib.boulder.ibm.com/infocenter/iadthelp/v7r0/topic/com.ibm.etools.iseries.langref.doc/ilcrefer17.htm) You don't get to use that "I'm Feeling Lucky" button much, but it works fine here. – mawburn Oct 09 '12 at 19:52
  • Well, I don't know what is up with my Google context, but Google tends to ignore special characters when I search. Every search that I tried returned results to generic, C operator lists-- none of which contained the "##" operator. In fact, I opened many of those pages and searched within the page-- didn't find this any where. – RLH Oct 09 '12 at 19:58
  • 1
    @H2CO3: The question you linked is not a precedent covering this one - it is much more about one technical detail than about the ## operator generally. – jpalecek Oct 09 '12 at 20:00
  • Yes, I read that question-- this is not a duplicate and, certainly, not an "exact" one. – RLH Oct 09 '12 at 20:01
  • @jpalecek this question asks fewer things than the one I linked - so it is a subset of the problem mentioned there. –  Oct 09 '12 at 20:02

4 Answers4

4

It's part of the preprocessor, concatenation of tokens, and concatn(x,y) is replaced by xy.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
4

## is the token pasting operator in C. It is used to concatenate two tokens.

Example:

#define PASTE(front, back) front ## back

then

PASTE(name, 1)    

creates the token name1

ouah
  • 142,963
  • 15
  • 272
  • 331
3

This is standard c preprocessor string concatenation operator

pm100
  • 48,078
  • 23
  • 82
  • 145
2

It is used to concatenate two tokens (in this case s1 and s2). More details here. It is standard C preprocessing, so every standards compliant compiler should handle it.

For instance:

concatn(a_, b) = 1;

Will macro to:

a_b = 1;
CrazyCasta
  • 26,917
  • 4
  • 45
  • 72