muppet wrote:

On Dec 12, 2004, at 3:12 AM, Sisyphus wrote:

SV * mysub(SV * a, SV * b, SV * three) {
if(three == &PL_sv_yes) // return b-a


i believe what you really want it

   if (three && SvTRUE (three))


Ummm ... since what I'm currently doing works flawlessly every time (afaict), I'm yet to be convinced that I "really want" anything else at all :-) .... at least, as regards operator overloading.


But in general terms - yes, I think you're quite right. I probably would have used SvTRUE() with my overload subs, except that I saw someone else had used the condition 'sv==&PL_sv_yes' - so I blindly followed suit. It's only in the last few days that I've come to ask myself "Just how the hell does that work ??".

SvTRUE() is true if the object is defined and true by the normal perl rules.

Problem was that *I* couldn't write any code (perl or XS) such that 'sv == &PL_sv_yes' was true. No matter how *I* was writing *my* code 'sv == &PL_sv_yes' was always returning false.


that's because PL_sv_yes is a statically-defined SV living off in the data segment someplace, and your pointers are on the heap or stack -- they will never match.

I reckon I'll understand this better when (if ever) I understand how overload.pm creates the PL_sv_yes (or PL_sv_no, as the case may be) and sends it to the overload subroutine as the third argument.


Thanks muppet.

Cheers,
Rob



Reply via email to