Re: Could anybody explain this macro for me?
On Nov 16, 12:56 pm, James Kanze <james.ka...@gmail.com> wrote:
On Nov 15, 11:21 pm, Old Wolf <oldw...@inspire.net.nz> wrote:
On Nov 15, 11:00 pm, James Kanze <james.ka...@gmail.com> wrote:
On Nov 15, 5:04 am, Old Wolf <oldw...@inspire.net.nz> wrote:
The ellipsis directly following the argument name, isn't in
any C standard. (Another poster suggests that it's a GCC
extension).
Might be. I would certainly expect that most
implementations supporting vararg templates support it
(except maybe in their strictest modes), much like they
support a final comma in an enum list. There is absolutely
no reason not to be orthogonal here (and I would consider
this a defect in the C standard).
Well, the gcc-3.4.4 I have here, running in standard mode,
just gives 'parse error' for:
int foo(int x...) { }
All I get for it in 4.2.1 (the only version I have available
here) is:
varargs.cc:8: warning: control reaches end of non-void function
That's compiled with
g++ -std=c++98 -pedantic -ffor-scope -fno-gnu-keywords -foperat=
or-
names -pipe -Wall -W -Wno-sign-compare -Wno-deprecated -Wno-non-
virtual-dtor -Wpointer-arith -Wno-unused -Wno-switch -Wno-missing-
braces -Wno-long-long -static-libgcc -ggdb3 -D_GLIBCXX_CONCEPT_CHECKS -
D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
(my standard options).
I've never encountered this form (without the comma), and I
usually do read the list of extensions in compiler
documentation when using a new compiler. Obviously you have
more experience with compilers than I do though!
Not so much compilers. According to the first edition of _The
C++ Programming Language__ (1986), the comma isn't legal.
According to the C90 or the C++98 standard, it is optional.
I've never seen a compiler that didn't accept it either way, but
then, I don't think I'd have noticed if it didn't; I can't
remember ever actually using varargs in C++.
Since both are required by the standard, I wouldn't expect to
find support for both mentionned in the compiler documentation.
I tried on another machine with gcc 4.0.1 .
g++ allows int foo(int x...) , gcc gives 'syntax error'.
I checked in C99 again and the grammar specification
doesn't seem to permit int foo(int x...) , the
relevant bits are:
direct-declarator:
direct-declarator ( parameter-type-list )
[snip]
parameter-type-list:
parameter-list
parameter-list , ...
Are you sure C90 allowed it?