----- Original Message ----- 
From: "Marvin Humphrey" <[EMAIL PROTECTED]>
To: <inline@perl.org>
Sent: Friday, July 08, 2005 11:29 AM
Subject: warnings with Inline C OOP recipe


> Greets,
>
> I added this line to the soldier program from the Inline C cookbook.
>
> use Inline Config => BUILD_NOISY => 1;
>
> ... and I exposed a bunch of warnings.  Here's one:
>
> Soldier_396a.xs: In function `get_name':
> Soldier_396a.xs:27: warning: cast to pointer from integer of
> different size
>
> This is the offending line of code:
>
> return ((Soldier*)SvIV(SvRV(obj)))->name;
>

I don't get those warnings - but then my IV is only 4 bytes. What's your 4
byte integer called ? .... short ? .... long ? Assuming it's a short:

return ((Soldier*)(unsigned short)SvIV(SvRV(obj)))->name;

I don't know how correct that is, and I'm unable to test very effectively.
All I could establish is that it still compiles without warning and runs
correctly for me if I:

return ((Soldier*)(unsigned long)SvIV(SvRV(obj)))->name;

But, of course, there's no resizing involved there. I did establish that the
following C program (which does involve resizing) compiles without any
warning or error.

#include <stdio.h>

int main(void) {
    unsigned long long a = 1234567; // 8 bytes for me
    int * z; // 4 bytes for me

    z = (int *)(int)a; // from 8 back to 4, and no warning.

    printf("Done\n");
    return 0;
}

But if I change 'z =(int*)(int)a;' to 'z = (int*)a;', then I get the
compiler warning:

warn.c:7: warning: cast to pointer from integer of different size

If something along those lines works, then you can probably set it up
correctly with appropriate pre-processor directives.

Cheers,
Rob

Reply via email to