Thread View: comp.std.c++
7 messages
7 total messages
Started by Laurent FRIGAULT
Sat, 13 Apr 1996 23:17
references and ellipsis
Author: Laurent FRIGAULT
Date: Sat, 13 Apr 1996 23:17
Date: Sat, 13 Apr 1996 23:17
45 lines
2007 bytes
2007 bytes
Hi,
I discover a problem when trying to use a C++ reference to an object
just before an ellipsis :
int foo(const int& aInt,...){
va_list params;
va_start(params,aInt);
// ...
va_end(params);
return 0;
}
I try this kind of code under several environnement and it compile well.
g++ 2.7.2 under sunos 4.1.3 give me a warning:
warning: second parameter of `va_start' not last named argument
but the code works fine.
Under NT with BC++ 4.51 and VC++ 2.1, I dont get any warning, but
the generated code is wrong.
If I replace the reference with a pointer or an object, the code works
in all cases. I couldn't find anything about a reference before an ellipsis
on the draft, so I presume that the code is correct.
Can someone confirm if this is correct or not.
If yes, I presume that the problem is in the implementation of va_start
that uses sizeof on the reference.
regards
Lolo
--
Laurent Frigault | frigault@gla.ecoledoc.ibp.fr
[ 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 ]
Re: references and ellipsis
Author: Steve Clamage
Date: Sun, 14 Apr 1996 12:34
Date: Sun, 14 Apr 1996 12:34
18 lines
1449 bytes
1449 bytes
frigault@gla.ecoledoc.ibp.fr (Laurent FRIGAULT) writes:
>I discover a problem when trying to use a C++ reference to an object
>just before an ellipsis :
>int foo(const int& aInt,...){
According the draft standard, the results of using a reference
type as the last pararmeter before the ellipsis (...) are
undefined. See section 18.7 "Other runtime support" [lib.support.runtime].
--
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 ]
Re: references and ellipsis
Author: Fergus Henderson
Date: Sun, 14 Apr 1996 15:08
Date: Sun, 14 Apr 1996 15:08
21 lines
1599 bytes
1599 bytes
clamage@Eng.Sun.COM (Steve Clamage) writes: >According the draft standard, the results of using a reference >type as the last pararmeter before the ellipsis (...) are >undefined. See section 18.7 "Other runtime support" [lib.support.runtime]. Is there any good reason why this has undefined behaviour rather than being ill-formed code? Surely this should be very easy for implementations to detect and diagnose. -- Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit" PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp. [ 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 ]
Re: references and ellipsis
Author: James Kanze US/ESC 60/3/141 #407...
Date: Mon, 15 Apr 1996 20:32
Date: Mon, 15 Apr 1996 20:32
31 lines
2211 bytes
2211 bytes
In article <4kr1p3$67g@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus
Henderson) writes:
|> clamage@Eng.Sun.COM (Steve Clamage) writes:
|> >According the draft standard, the results of using a reference
|> >type as the last pararmeter before the ellipsis (...) are
|> >undefined. See section 18.7 "Other runtime support" [lib.support.runtime].
|> Is there any good reason why this has undefined behaviour rather than
|> being ill-formed code? Surely this should be very easy for implementations
|> to detect and diagnose.
Historical reasons, no doubt. Declare the last parameter a char in C,
and you also get undefined behavior.
And it's surely no more difficult to diagnose a double underscore (and
at least one compiler does), which is also `undefined behavior'.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
-- A la recherche d'une activité dans une region francophone
[ 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 ]
Re: references and ellipsis
Author: James Kanze US/ESC 60/3/141 #407...
Date: Mon, 15 Apr 1996 20:46
Date: Mon, 15 Apr 1996 20:46
29 lines
2252 bytes
2252 bytes
In article <4kr1p3$67g@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus
Henderson) writes:
|> clamage@Eng.Sun.COM (Steve Clamage) writes:
|> >According the draft standard, the results of using a reference
|> >type as the last pararmeter before the ellipsis (...) are
|> >undefined. See section 18.7 "Other runtime support" [lib.support.runtime].
|> Is there any good reason why this has undefined behaviour rather than
|> being ill-formed code? Surely this should be very easy for implementations
|> to detect and diagnose.
Hysterica^H^H^H^H^H^H^Horical reasons, no doubt. Declare the last
parameter a char in C, and you also get undefined behavior.
And it's surely no more difficult to diagnose a double underscore (and
at least one compiler does), which is also `undefined behavior'.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
-- A la recherche d'une activiti dans une region francophone
---
[ 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 ]
Re: references and ellipsis
Author: Fergus Henderson
Date: Tue, 16 Apr 1996 20:14
Date: Tue, 16 Apr 1996 20:14
39 lines
2706 bytes
2706 bytes
kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) writes:
>fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
>
>|> clamage@Eng.Sun.COM (Steve Clamage) writes:
>
>|> >According the draft standard, the results of using a reference
>|> >type as the last pararmeter before the ellipsis (...) are
>|> >undefined. See section 18.7 "Other runtime support" [lib.support.runtime].
>
>|> Is there any good reason why this has undefined behaviour rather than
>|> being ill-formed code? Surely this should be very easy for
>|> implementations to detect and diagnose.
>
>Hysterica^H^H^H^H^H^H^Horical reasons, no doubt. Declare the last
>parameter a char in C, and you also get undefined behavior.
>
>And it's surely no more difficult to diagnose a double underscore (and
>at least one compiler does), which is also `undefined behavior'.
No, I think providing useful diagnostics for use of references before
an elipsis is indeed less difficult than providing useful diagnostics
for use of double underscores. It's difficult (though by no means
impossible, of course) for implementations to issue diagnostics for
uses of the implementation's part of the namespace without also issuing
diagnostics for definitions in the system header files or in code which
merely references macros defined in the system header files.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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
]
Re: references and ellipsis
Author: Steven Correll
Date: Thu, 18 Apr 1996 15:02
Date: Thu, 18 Apr 1996 15:02
36 lines
2820 bytes
2820 bytes
>>|> clamage@Eng.Sun.COM (Steve Clamage) writes: >>|> >According the draft standard, the results of using a reference >>|> >type as the last pararmeter before the ellipsis (...) are >>|> >undefined. See section 18.7 "Other runtime support" [lib.support.runtime]. Here we have a case where the user is relies on "undefined" behavior; the user can easily fix the program not to do this; every compiler can detect it; and some but not all compilers will generate surprising and undesirable behavior. In such circumstances, should the language standard require every compiler to generate a diagnostic? I say yes, but I admit it's a matter of taste. Those who disagree should note, however, that both C and Fortran have a history of having to change a lot of their "no" answers to "yes" answers the second time around: both ANSI C and Fortran 90 are far stricter than their predecessors, because experienced programmers seem to prefer to maximize the probability that their code will work when ported to another place, rather than to take advantage of the possibility that a few implementations might do something handy for the "undefined" cases. In the case of Fortran 90, some of the pressure for stricter diagnostics even came from implementors who were sick of having to provide a "VMS" switch to implement undefined things the way the Vax did, a "Cray" switch to implement undefined things the way the Cray did, etc, so as to keep their users content. Members of the committee should realize that in many cases, if the de jure standard says "undefined" and doesn't require a diagnostic, the de facto standard will be "implementors have to do whatever Microsoft does". -- Steven Correll == PO Box 66625, Scotts Valley, CA 95067 == sjc@netcom.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 ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads