1

I discovered this in the source code for the Unreal Engine 4 and didn't recognize it. The specific instance of it is:

#undef UCLASS

#define UCLASS(...) \
ARadialForceActor_EVENTPARM

I'm a fairly new programmer and this kind of macro is unfamiliar to me. My guess was that it is defining a macro that will take every overloaded version of the function UCLASS (in other words, every instance of a function named UCLASS, regardless of the type and number of parameters) and replace it with the variable ARadialForceActor_EVENTPARM. Is that correct? If not, does anyone know what it means? I tried writing a code snippet to test this, but it returned error: "." may not appear in macro parameter list. I'll include it below, in case I was right about the macro, in which case I would appreciate it if someone could point out where I went wrong in my code:

#include <iostream>

#define foo( . . . ) bar

using namespace std;

int foo() {cout <<54321<<endl;}

int main()
{  bar=12345;
   cout<<bar<<endl;

   return 0;
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Max North
  • 13
  • 2
  • It's a [variaidic macro](http://en.cppreference.com/w/cpp/preprocessor/replace). It only works as of C++11. – chris Jun 09 '14 at 01:30
  • 1
    Why did you add the spaces? – Retired Ninja Jun 09 '14 at 01:31
  • @ Retired Ninja - Oh, yeah, that's a typo. I tried both, and either way it produces the same error – Max North Jun 09 '14 at 01:39
  • @Jongware this is **not** a duplicate, your linked question asks how to define a variadic macro - while this one asks what `...` means in the context. Just because two questions have a similar answer does **not** mean that they are duplicates. – Filip Roséen - refp Jun 09 '14 at 06:16

2 Answers2

1

Your guess of the meaning of #define foo(...) bar is correct. Your error is in thinking that . . . and ... are the same; they are not. ... must be written with no spaces between the dots. If I modify your program to read

#include <iostream>

#define foo(...) bar

using std::cout;

int foo()
{
   cout << 54321 << '\n';
}

int main()
{
   bar = 12345;
   cout << bar << '\n';
   return 0;
}

(please take note of other stylistic corrections; future readers of your code will thank you)

then I get error messages consistent with foo() having been replaced with bar in the function definition, as if you had written

int bar
{
    cout << 54321 << '\n';
}

which is, in fact, what this tells the preprocessor to do. (The preprocessor, as always, has no understanding of the syntax of the language proper.)

zwol
  • 135,547
  • 38
  • 252
  • 361
  • So I finally figured out the spaces thing just before Zack's comment. Now I understand what Retired Ninja was referring to. Thanks for the many speedy responses everyone! – Max North Jun 09 '14 at 02:14
0
#define FOO(...)

this means your macro can accept variable number of arguments. See here for details.

deeiip
  • 3,319
  • 2
  • 22
  • 33