5

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.

Community
  • 1
  • 1
FireAphis
  • 6,185
  • 7
  • 38
  • 60

2 Answers2

3

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;
}
CB Bailey
  • 648,528
  • 94
  • 608
  • 638
  • variables defined in anonymous namespace cannot be 'extern'ed outside the file where the namespace resides. – Donotalo Sep 02 '10 at 07:33
1

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
  • 99,411
  • 44
  • 178
  • 249