Re: [C] return statement in void function?
From: Anthony Borla (ajborla_at_bigpond.com)
Date: 01/12/04
- Previous message: Chris \( Val \): "Re: [C++] Casting void* pointers within different scope"
- In reply to: Arthur J. O'Dwyer: "Re: [C] return statement in void function?"
- Next in thread: Lyn Powell: "Re: [C] return statement in void function?"
- Reply: Lyn Powell: "Re: [C] return statement in void function?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 12 Jan 2004 13:15:28 GMT
"Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> wrote in message
news:Pine.LNX.4.58-036.0401120104290.19968@unix46.andrew.cmu.edu...
>
> On Mon, 12 Jan 2004, Anthony Borla wrote:
> >
> > You may be interested to know that you can do this
> [in C++, that is]:
> >
> > void f() { return void(); }
> >
> > as is this:
> >
> > void g() {}
> > void h() { return g(); }
> >
> > Yes, it may seem strange, but it is allowed [I suspect] to
> > maintain syntactic consistency.
>
> However, both of these tricks are not allowed in C.
>
I only noticed the [C] identifier in the Subject field a few hours *after* I
posted - how's that for being blinkered :) ?
I suppose one benefit of my post, though, was to provide the OP with *more*
information than was required [got to put a positive spin on it somehow ;)
!].
>
> C++, as far as I know, allows them; but the first is
> a syntax error in C and the second one, despite maybe
> being "consistent," doesn't have any advantage
> over
>
> void h() { g(); return; }
>
> which is probably why C doesn't bother to allow it.
>
This:
void f() { return void(); }
is not legal C because the language doesn't support temporary objects [let
alone permanent ones ;)].
I suspect the following:
void g() {}
void h() { return g(); }
is also allowed in C++ as a consequence of temporary object support since:
return g();
is probably optimised to:
return void();
Thus, this is illegal in C for the same reason ?
Cheers,
Anthony Borla
- Previous message: Chris \( Val \): "Re: [C++] Casting void* pointers within different scope"
- In reply to: Arthur J. O'Dwyer: "Re: [C] return statement in void function?"
- Next in thread: Lyn Powell: "Re: [C] return statement in void function?"
- Reply: Lyn Powell: "Re: [C] return statement in void function?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]