[comp.lang.c++] Use of Ellipsis on c++

consp06@bingsuns.cc.binghamton.edu (Robert Konigsberg) (04/19/91)

I'm writing my first c++ Class - Matrices (Ooooohh)

The Constructor is defined as follows:

void Matrix(unsigned xv=1, yv=1, ...) {Alloc(xv,yv); SetZero();
                                       Values(...);};

See?  It initializes the size in Alloc.  It sets all the values to
zero in SetZero, and then takes the values from ... in inserts them
into the matrix.  Granted, this makes SetZero redundant, but it
doesn't if there is nothing for the ellipsis.

Now, if, later on, I do the following:

Matrix a(2,2,1,2,3,4),b,c;

It defines a as
[ 0 0 ]
[ 0 0 ]

b and c as 
[ 0 ]

a should be
[ 1 2 ]
[ 3 4 ]

Why isn't it?  I know that if I just rewrite my code to take care of
the variable arguments directly within Matrix, I'll have no problem,
but if I do that, then it'll waste code.  I still need Values if I
want to redefine the values.  Why is this happening?

			-Rob Konigsberg

rfg@NCD.COM (Ron Guilmette) (04/19/91)

In article <1991Apr18.203147.19510@bingvaxu.cc.binghamton.edu> consp06@bingsuns.cc.binghamton.edu (Robert Konigsberg) writes:
>I'm writing my first c++ Class - Matrices (Ooooohh)
>
>The Constructor is defined as follows:
>
>void Matrix(unsigned xv=1, yv=1, ...) {Alloc(xv,yv); SetZero();
>                                       Values(...);};
>
>See?  It initializes the size in Alloc.  It sets all the values to
>zero in SetZero, and then takes the values from ... in inserts them
>into the matrix...

You have apparently uncovered an interesting bug in your C++ language
processor (which I suspect is cfront, but I'm not sure).

An ellipsis (i.e. `...') is *not*, I repeat *not* a variable nor is it
anything even remotely like a variable.  Thus, it is also not a formal
parameter and it should be illegal to try to "pass" an ellipsis to
another function.

The ellipsis is a special token whose only legitimate use is as a way
of indicating that a given function may (or may not) take additional
parameters (beyond those listed to the left of the ellipsis), all of
which have unspecified types.

In order to access these additional *actual* parameter values (if any)
you must use the va_start, va_arg, and va_end macros.  (See your local
manpage under `stdarg' or your ANSI C standard document.)

So the long and the short of it is that you have done something (i.e.
trying to "pass" an ellipsis) which is illegal in both ANSI C and in
C++.

The fact that your C++ language processor let you get away with this
indicates that there is bug in that product.

(Note that some C compilers produced by AT&T have an interesting implementation
of the va_start macro which assumes that the underlying C compiler *does*
allow one to say:

		&...

within the body of a function.  I suspect that the ability to refer to `...'
within the body of a function may have been carried over into other AT&T
products, but I have no way of knowing. Cfront 2.1 properly complains if
you try to "pass" an ellipsis.)

So what C++ language processor *are* you using?
-- 

// Ron ("Loose Cannon") Guilmette
// Internet: rfg@ncd.com      uucp: ...uunet!lupine!rfg
// New motto:  If it ain't broke, try using a bigger hammer.