3

Possible Duplicates:
Macro expansion in C++
What is the purpose of the ## operator in C++, and what is it called?

What does "##" symbol mean in C++? I came across with it while I was reading someone's source code. More specifically, what does this statement mean:

if ( v > ## = 0.1 * threshold )
Community
  • 1
  • 1
small_potato
  • 3,127
  • 5
  • 39
  • 45

4 Answers4

7

In a #define macro, ## is a preprocessor token, which says to paste the surrounding two things together. So assuming you saw this within a #define, it is a very strange way of writing

if ( v >= 0.1 * threshold )

If you already subsituted either the > or =, it's not quite so strange. Just a somewhat strange trick.

aschepler
  • 70,891
  • 9
  • 107
  • 161
2

It's a preprocessor token:

http://msdn.microsoft.com/en-us/library/09dwwt6y%28v=vs.80%29.aspx

Joe
  • 41,484
  • 20
  • 104
  • 125
1

It means nothing. This is an error.

Are you sure that the code after ## isn't a comment, and that the conditional is not continued properly on the next ensuing line?

Alternatively, the code you pasted may be part of a line that constitutes a macro definition (but you showed no evidence of that, so I won't answer that different question here).

(You see how context matters in questions like this?)

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
1

## tells cpp to paste the tokens before and after it together. In this case, I would have to guess that for some reason the programmer needed to avoid having an actual >= token, possibly to avoid confusing some other preprocessor (documentation generator or whatever), so has cpp assemble the >= from its components.

geekosaur
  • 59,309
  • 11
  • 123
  • 114