Topic: return and void
Author: ianmcc@lorentz.leidenuniv.nl (Ian McCulloch)
Date: Wed, 20 Nov 2002 19:31:27 +0000 (UTC) Raw View
scottm@toast.net ("Scott Mayo") wrote in message news:<3dd08aad@news.toast.net>...
> Last I knew, this wasn't legal in C++ or C:
>
> extern void a(); //a, a function returning void
> void b() { return a(); } //b calls a() and returns void
>
> As far as I can see, supporting this is harmless, and maybe even a
> minor simplification for compilers. It's not useful when coding
> by hand, but a few times when writing code-generators I
> really wished it was available. Is there a reason this cannot be
> added to C++?
As everyone else has said, this is already part of C++.
However, I refute your statement that it is not useful when coding by
hand. On the contrary, I think it is excellent style when writing
delegation functions to always 'return' the value of the delegatee
(err, is that correct English?), even if it is void. This helps catch
problems if the return type is changed, and also fixes the annoying
asymmetry between returning void and returning anything else:
struct myclass
{
int foo();
char* bar();
void baz();
};
struct contains_myclass
{
myclass c;
int foo() { return c.foo(); }
char* bar() { return c.bar(); }
void baz() { c.baz(); } // why different notation here?
};
If the return type of myclass::baz is changed to something else, then
the above code will silently drop the return value. If
contains_myclass::baz is written in the same style as the other
delegation functions, then the compiler will catch the bug.
Cheers,
Ian McCulloch
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net (James Kuyper)
Date: Mon, 18 Nov 2002 15:12:23 +0000 (UTC) Raw View
Ron Natalie wrote:
>
> ""Scott Mayo"" <scottm@toast.net> wrote in message news:3dd08aad@news.toast.net...
>
> > As far as I can see, supporting this is harmless, and maybe even a
> > minor simplification for compilers. It's not useful when coding
> > by hand, but a few times when writing code-generators I
> > really wished it was available. Is there a reason this cannot be
> > added to C++?
>
> templates.
Simplifying the writing of templates is the reason why it WAS added to
C++.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ron@sensor.com ("Ron Natalie")
Date: Mon, 18 Nov 2002 16:12:22 +0000 (UTC) Raw View
"James Kuyper" <kuyper@wizard.net> wrote in message news:3DD9030C.173D25@wizard.net...
> Ron Natalie wrote:
> >
> > ""Scott Mayo"" <scottm@toast.net> wrote in message news:3dd08aad@news.toast.net...
> >
> > > As far as I can see, supporting this is harmless, and maybe even a
> > > minor simplification for compilers. It's not useful when coding
> > > by hand, but a few times when writing code-generators I
> > > really wished it was available. Is there a reason this cannot be
> > > added to C++?
> >
> > templates.
>
> Simplifying the writing of templates is the reason why it WAS added to
> C++.
Yes, that was the point I was trying to make. I should have been less terse.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: scottm@toast.net ("Scott Mayo")
Date: Tue, 12 Nov 2002 05:10:08 +0000 (UTC) Raw View
Last I knew, this wasn't legal in C++ or C:
extern void a(); //a, a function returning void
void b() { return a(); } //b calls a() and returns void
As far as I can see, supporting this is harmless, and maybe even a
minor simplification for compilers. It's not useful when coding
by hand, but a few times when writing code-generators I
really wished it was available. Is there a reason this cannot be
added to C++?
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis.glassborow@ntlworld.com (Francis Glassborow)
Date: Tue, 12 Nov 2002 12:39:20 +0000 (UTC) Raw View
In article <3dd08aad@news.toast.net>, Scott Mayo <scottm@toast.net>
writes
>Last I knew, this wasn't legal in C++ or C:
>
>extern void a(); //a, a function returning void
>void b() { return a(); } //b calls a() and returns void
It has been legal C++ for as long as the C++ Standard has existed. Of
course that does not mean that all compilers understand that :-)
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: gdr@integrable-solutions.net (Gabriel Dos Reis)
Date: Tue, 12 Nov 2002 12:39:24 +0000 (UTC) Raw View
scottm@toast.net ("Scott Mayo") writes:
| Last I knew, this wasn't legal in C++ or C:
|
| extern void a(); //a, a function returning void
| void b() { return a(); } //b calls a() and returns void
You are misinformed: that is a valid construct in C++.
--
Gabriel Dos Reis, gdr@integrable-solutions.net
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: anthony.williamsNOSPAM@anthonyw.cjb.net (Anthony Williams)
Date: Tue, 12 Nov 2002 17:54:28 +0000 (UTC) Raw View
scottm@toast.net ("Scott Mayo") writes:
> Last I knew, this wasn't legal in C++ or C:
>
> extern void a(); //a, a function returning void
> void b() { return a(); } //b calls a() and returns void
Then you last checked before C++ was standardized, because you _can_ do this
in standard C++. Not all compilers let you, but not all compilers are fully
standard-conforming.
Anthony
--
Anthony Williams
Senior Software Engineer, Beran Instruments Ltd.
Remove NOSPAM when replying, for timely response.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: jpotter@falcon.lhup.edu (John Potter)
Date: Tue, 12 Nov 2002 17:54:32 +0000 (UTC) Raw View
On Tue, 12 Nov 2002 05:10:08 +0000 (UTC), scottm@toast.net ("Scott
Mayo") wrote:
> Last I knew, this wasn't legal in C++ or C:
> extern void a(); //a, a function returning void
> void b() { return a(); } //b calls a() and returns void
> As far as I can see, supporting this is harmless, and maybe even a
> minor simplification for compilers. It's not useful when coding
> by hand, but a few times when writing code-generators I
> really wished it was available. Is there a reason this cannot be
> added to C++?
6.6.3/3 seems to be a serious deterrent.
John
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: agriff@tin.it (Andrea Griffini)
Date: Tue, 12 Nov 2002 17:54:32 +0000 (UTC) Raw View
On Tue, 12 Nov 2002 05:10:08 +0000 (UTC), scottm@toast.net ("Scott
Mayo") wrote:
>Is there a reason this cannot be
>added to C++?
I suppose the only reason is that it's already there.
There is a specific rule for this in my unofficial
docs listed as 6.3.3/3 [stmt.return].
My guess is that this apparently strange extension has
been added to simplify writing template code.
Andrea
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: gennaro_prota@yahoo.com (Gennaro Prota)
Date: Tue, 12 Nov 2002 19:44:51 +0000 (UTC) Raw View
On Tue, 12 Nov 2002 17:54:32 +0000 (UTC), jpotter@falcon.lhup.edu
(John Potter) wrote:
>6.6.3/3 seems to be a serious deterrent.
The next question seems to be: why not
void f();
void g();
int main() {
f(g());
}
? Ok ok... put that gun away!!! Just joking... :-)
Genny.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ron@sensor.com ("Ron Natalie")
Date: Tue, 12 Nov 2002 22:09:13 +0000 (UTC) Raw View
""Scott Mayo"" <scottm@toast.net> wrote in message news:3dd08aad@news.toast.net...
> As far as I can see, supporting this is harmless, and maybe even a
> minor simplification for compilers. It's not useful when coding
> by hand, but a few times when writing code-generators I
> really wished it was available. Is there a reason this cannot be
> added to C++?
templates.
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]