Topic: Methods with variable number arguments lik


Author: comeau@panix.com (Greg Comeau)
Date: 1997/01/10
Raw View
In article <rf5sp4dviro.fsf@vx.cit.alcatel.fr> James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:
>comeau@panix.com (Greg Comeau) writes:
>
>|>  In article <rf5n2ur5d58.fsf@vx.cit.alcatel.fr> James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:
>
>|>  > In fact, although the standard doesn't
>|>  >give him formally the right, he could probably also specify different
>|>  >syntax;
>|>
>|>  I think this is carrying the point too far.  There is no liberty for
>|>  having nested languages with this option.  extern "blah" does not mean
>|>  "enter the other language".  It means "give me a fighting chance to talk
>|>  to it".
>
>This is certainly the intent of the standard.  On the other hand, once
>you venture into "implementation defined", who cares about the
>standard:-).

I see the smiley but still believe you believe this.
I mean, sure, this dimension of things is there, but really,
when alternative are there that allows you to still care about
the standard, they should definitely be considered, even if they
are not considered the most optimal choices.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
               Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
 Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: comeau@panix.com (Greg Comeau)
Date: 1997/01/06
Raw View
In article <rf5n2ur5d58.fsf@vx.cit.alcatel.fr> James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:
>hpa@transmeta.com (H. Peter Anvin) writes:
>|>  > In article 398F@dit.ou.dk, "Morten M. Christensen" <mmc@dit.ou.dk> writes:
>|>  > but you can't write foo in portable C++ (and not at all in C). The looser
>|>  > rule in C++ allowing such declarations supports functions written
>|>  > in, say, assembler, that depend on the argument-passing conventions of
>|>  > the particular C++ compiler.
>|>
>|>  This also becomes useful since C++ is one of the very few languages in
>|>  the world to even define a syntax for linking to other languages.  For
>|>  example, PL/1 supports varadic functions and provides a counter to the
>|>  number of arguments.  Hence the declaration
>|>
>|>   extern "PL/1" foobar(...);
>|>
>|>  may not be *portable* per se, but at least it is syntactically valid
>|>  C++.
>
>Only if the implementor says so:-).  The meaning (and legality) of
>anything other than "C" or "C++" in the extern declaration are
>implementation defined.

Even aspects of "C" and "C++" are implementation defined.

>   Presumably, the implementor could also specify
>different semantics for what followed, e.g.: following `extern
>"FORTRAN"`, all arguments are in fact pass by reference, even when you
>declare them as pass by value.

Right, as the semantics (the semantics of the linkage that is)
are implementation defined, it is up to the implementor.

> In fact, although the standard doesn't
>give him formally the right, he could probably also specify different
>syntax;

I think this is carrying the point too far.  There is no liberty for
having nested languages with this option.  extern "blah" does not mean
"enter the other language".  It means "give me a fighting chance to talk
to it".

> as soon as you write `extern "FOO"', you have left the realm of
>portable C++, and so might as well use any other extensions as well.

Na, this too is pushing it.
If any "machinery" is required, it is best done elsewhere.
Using extensions is almost always at the wrong level.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
               Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
 Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: comeau@panix.com (Greg Comeau)
Date: 1997/01/06
Raw View
In article <rf5n2ur5d58.fsf@vx.cit.alcatel.fr> James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:
>hpa@transmeta.com (H. Peter Anvin) writes:
>
>|>  >
>|>  > In article 398F@dit.ou.dk, "Morten M. Christensen" <mmc@dit.ou.dk> writes:
>|>  > >
>|>  > >Is it legal in standard C++ to have methods with a variable
>|>  > >number of arguments like printf ?
>|>  >
>|>  > Yes. The <varargs.h> C header and macros are also part of C++. A
>|>  > valid C program using variable arg lists is also valid in C++.
>|>  >
>|>
>|>  Don't you mean <stdargs.h>?  <varargs.h> is AFAIK K&R.
>
>Just a nit: <varargs.h> isn't even K&R.  As far as I know, it was
>introduced in the Berkley port of pcc, and spread because Berkely Unix
>was the de facto standard Unix for a while.

A number of people did up mechanisms of similar sorts.  I know I did.
I am fairly certain though that Andy Koenig was the one who came up with
the "formal" stuff found in varargs and eventually incorporated into stdargs.

>  But programs using
><varargs.h> have never been portable.

Not totally, but its mileage was quite well.
Of course, portability is relative in some cases.
Of course as well, the ... token bought a lot more.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
               Producers of Comeau C++ 4.0 front-end pre-release
****WEB: http://www.comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
 Here:comeau@comeaucomputing.com / BIX:comeau or comeau@bix.com / CIS:72331,3421
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/01/07
Raw View
comeau@panix.com (Greg Comeau) writes:

|>  In article <rf5n2ur5d58.fsf@vx.cit.alcatel.fr> James Kanze <james-albert.kanze@vx.cit.alcatel.fr> writes:

|>  > In fact, although the standard doesn't
|>  >give him formally the right, he could probably also specify different
|>  >syntax;
|>
|>  I think this is carrying the point too far.  There is no liberty for
|>  having nested languages with this option.  extern "blah" does not mean
|>  "enter the other language".  It means "give me a fighting chance to talk
|>  to it".

This is certainly the intent of the standard.  On the other hand, once
you venture into "implementation defined", who cares about the
standard:-).

--
James Kanze         home:     kanze@gabi-soft.fr        +33 (0)3 88 14 49 00
                    office:   kanze@vx.cit.alcatel.fr   +33 (0)1 69 63 14 54
GABI Software, Sarl., 8 rue des Francs Bourgeois, F-67000 Strasbourg, France
       -- Conseils en informatique industrielle --
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: hpa@transmeta.com (H. Peter Anvin)
Date: 1997/01/02
Raw View
Followup to:  <199612191956.LAA22620@taumet.eng.sun.com>
By author:    stephen.clamage@Eng (Steve Clamage)
In newsgroup: comp.std.c++
>
> In article 398F@dit.ou.dk, "Morten M. Christensen" <mmc@dit.ou.dk> writes:
> >
> >Is it legal in standard C++ to have methods with a variable
> >number of arguments like printf ?
>
> Yes. The <varargs.h> C header and macros are also part of C++. A
> valid C program using variable arg lists is also valid in C++.
>

Don't you mean <stdargs.h>?  <varargs.h> is AFAIK K&R.

> but you can't write foo in portable C++ (and not at all in C). The looser
> rule in C++ allowing such declarations supports functions written
> in, say, assembler, that depend on the argument-passing conventions of
> the particular C++ compiler.

This also becomes useful since C++ is one of the very few languages in
the world to even define a syntax for linking to other languages.  For
example, PL/1 supports varadic functions and provides a counter to the
number of arguments.  Hence the declaration

 extern "PL/1" foobar(...);

may not be *portable* per se, but at least it is syntactically valid
C++.

 -hpa
--
This space intentionally has nothing but text explaining why this
space has nothing but text explaining why this space would otherwise
have been left blank, and would otherwise have been left blank.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/01/03
Raw View
hpa@transmeta.com (H. Peter Anvin) writes:

|>  >
|>  > In article 398F@dit.ou.dk, "Morten M. Christensen" <mmc@dit.ou.dk> writes:
|>  > >
|>  > >Is it legal in standard C++ to have methods with a variable
|>  > >number of arguments like printf ?
|>  >
|>  > Yes. The <varargs.h> C header and macros are also part of C++. A
|>  > valid C program using variable arg lists is also valid in C++.
|>  >
|>
|>  Don't you mean <stdargs.h>?  <varargs.h> is AFAIK K&R.

Just a nit: <varargs.h> isn't even K&R.  As far as I know, it was
introduced in the Berkley port of pcc, and spread because Berkely Unix
was the de facto standard Unix for a while.  But programs using
<varargs.h> have never been portable.

|>  > but you can't write foo in portable C++ (and not at all in C). The looser
|>  > rule in C++ allowing such declarations supports functions written
|>  > in, say, assembler, that depend on the argument-passing conventions of
|>  > the particular C++ compiler.
|>
|>  This also becomes useful since C++ is one of the very few languages in
|>  the world to even define a syntax for linking to other languages.  For
|>  example, PL/1 supports varadic functions and provides a counter to the
|>  number of arguments.  Hence the declaration
|>
|>   extern "PL/1" foobar(...);
|>
|>  may not be *portable* per se, but at least it is syntactically valid
|>  C++.

Only if the implementor says so:-).  The meaning (and legality) of
anything other than "C" or "C++" in the extern declaration are
implementation defined.  Presumably, the implementor could also specify
different semantics for what followed, e.g.: following `extern
"FORTRAN"`, all arguments are in fact pass by reference, even when you
declare them as pass by value.  In fact, although the standard doesn't
give him formally the right, he could probably also specify different
syntax; as soon as you write `extern "FOO"', you have left the realm of
portable C++, and so might as well use any other extensions as well.

--
James Kanze         home:     kanze@gabi-soft.fr        +33 (0)3 88 14 49 00
                    office:   kanze@vx.cit.alcatel.fr   +33 (0)1 69 63 14 54
GABI Software, Sarl., 8 rue des Francs Bourgeois, F-67000 Strasbourg, France
       -- Conseils en informatique industrielle --


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: design@netcom.com (Chris Waters)
Date: 1996/12/26
Raw View
In article <199612191956.LAA22620@taumet.eng.sun.com>,
Steve Clamage <stephen.clamage@Eng> wrote:

>If you stick with the <varargs.h> facilities, you can write portable
>variable-argument functions in C and in C++.

Er, please feel free to correct me if I'm wrong, but I don't think you
can write portable code in *any* language if you use the "<varargs.h>
facilities."  Now, if you use the "<stdargs.h> facilities," OTOH....

Ok, <varargs.h> is supported on a lot of platforms, but it's not, to the
best of my knowledge, compliant with any standard (and this *is*
comp.std.c++).  As far as C++ goes, I think you might need to use:

    #include <cstdarg>

rather than

    #include <stdarg.h>

to be compliant with the latest draft.  But it is the same set of
facilities, so that's a quibble at best.  I realize that this whole post
may seem like somewhat of a quibble, but as someone who has been
struggling for years to get organizations and programmers to recognize
which practices are and are not standards-compliant, it doesn't *seem*
like a mere quibble to me.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: stephen.clamage@Eng (Steve Clamage)
Date: 1996/12/19
Raw View
In article 398F@dit.ou.dk, "Morten M. Christensen" <mmc@dit.ou.dk> writes:
>
>Is it legal in standard C++ to have methods with a variable
>number of arguments like printf ?

Yes. The <varargs.h> C header and macros are also part of C++. A
valid C program using variable arg lists is also valid in C++.

> I.e. Are the methods below
>legal ?
>
>class X                // An example:
>{
> public:
> void printf(...);     // Accepted by BC++ and Visual C++
> void operator()(...); // Accepted by BC++, Visual C++ "crashes" on
>this.
>};

Declarations like
 void foo(...);
are not valid in C, but they are in C++. C requires at least one fixed
argument before the ellipsis "...".

On the other hand, C++ provides no mechanism for accessing any of the
actual arguments unless the function declares a fixed argument. You can
declare
 void foo(...);
but you can't write foo in portable C++ (and not at all in C). The looser
rule in C++ allowing such declarations supports functions written
in, say, assembler, that depend on the argument-passing conventions of
the particular C++ compiler.

If you stick with the <varargs.h> facilities, you can write portable
variable-argument functions in C and in C++.

---
Steve Clamage, stephen.clamage@eng.sun.com




[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]