Front page | perl.perl5.porters |
Postings from December 2012
Re: SvUPGRADE and void
Thread Previous
|
Thread Next
From:
Peter Martini
Date:
December 14, 2012 20:26
Subject:
Re: SvUPGRADE and void
Message ID:
CAFyW6MRS9d5kGoU_viQCxdy2zoGkgA_+b544Fr-wkA9rQk-pHQ@mail.gmail.com
On Fri, Dec 14, 2012 at 3:06 PM, Nicholas Clark <nick@ccl4.org> wrote:
> 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
Err, point taken. Maybe then:
#define SvUPGRADE(sv,mt) do_nothing, (SvTYPE(sv) >= (mt) ||
(sv_upgrade(sv, mt), 1))
?
No STMT_START, STMT_END to worry about, it's still a single statement
so if(foo) SvUPGRADE(sv,mt) still works, and the void will apply to
the already void function.
I might be missing something else obvious this time :-)
(forgot to hit Reply All the first time I sent this)
Thread Previous
|
Thread Next