develooper Front page | perl.perl5.porters | Postings from December 2012

Re: SvUPGRADE and void

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
December 14, 2012 20:06
Subject:
Re: SvUPGRADE and void
Message ID:
20121214200619.GT5653@plum.flirble.org
On Fri, Dec 14, 2012 at 02:59:09PM -0500, Peter Martini wrote:
> On Fri, Dec 14, 2012 at 12:48 PM, Dave Mitchell <davem@iabyn.com> wrote:
> > On Fri, Dec 14, 2012 at 03:22:15PM +0000, Dave Mitchell wrote:

> >> Ok, I've bitten the bullet.
> >
> > ... and broken g++.
> >
> > Can anyone suggest a definition for SvUPGRADE that works for both of the
> > forms
> >
> >     SvUPGRADE(...);
> >     (void)SvUPGRADE(...);
> >
> > on gcc, clang and g++, and doesn't generate warnings?


> I can't think of a suitable no-op, but let's say we have a function:
> 
> void do_nothing(void){;}
> 
> Couldn't we make SvUPGRADE into:
> 
> do_nothing; STMT_START { if (SvTYPE(sv) < (mt)) sv_upgrade(sv, mt); } STMT_END
> 
> ?

I *think* that the intent of STMT_START .... STMT_END is so that you can cook
up a macro that behaves just like a statement. ie

    if (foo)
        SvUPGRADE(...);

is supposed to not to surprise, and behave identically to

    if (foo) {
        SvUPGRADE(...);
    }

> That should satisfy the sanity checks of both, and I would think the
> do_nothing should be optimized away.

but I *think* that it fails to behave like a single statement.

(I'd be very happy to be wrong)

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About