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,007
  • 4
  • 37
  • 42

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
  • 68,873
  • 9
  • 101
  • 151
2

It's a preprocessor token:

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

Joe
  • 40,031
  • 18
  • 107
  • 123
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
  • 369,052
  • 73
  • 620
  • 1,021
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
  • 56,235
  • 11
  • 119
  • 111