tags:

views:

103

answers:

2

What is the meaning of the following declaration:

char (& test(...))[2];

I pasted it inside a function body as is and it compiles all right. I don't know what I can do with it but it passes the compilation.

I've encountered something similar in this answer.

+3  A: 

It's the declaration of a function taking a variable argument list and returning a reference to an array of 2 char.

Note that if define a function like this the parameters are inaccessible (via standard means) as the <cstdarg> macros require a variable argument list to follow a named parameter.

If you like, you can defined a function with this declaration and return a reference to suitable array. You can call it with any parameters, subject to the restrictions for ... parameters which include the restrictions that passing non-POD class types causes undefined behaviour.

E.g.

namespace
{
    char samplearray[2];
}

char (& test(...))[2]
{
    return samplearray;
}
Charles Bailey
What does an anonymous namespace do in the above code?
Vulcan Eager
variables defined in anonymous namespace cannot be 'extern'ed outside the file where the namespace resides.
Donotalo
+1  A: 

Declare test as a vararg function returning a reference to an array of 2 chars

A useful site for de-mangling such declarations is cdecl: C gibberish <-> English (although it doesn't understand varargs and is C oriented rather than C++).

Motti
Wow that's a funny site. I can just sit and hit "refresh" for hours :)
FireAphis
@FireAphis that's when you know it's time to seek professional help ;o)
Motti