On Thu, Jun 12, 2008 at 1:40 PM, Lisandro Dalcin <[EMAIL PROTECTED]> wrote:
> On 6/12/08, Stefan Behnel <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>>  regarding the second issue below, a simple cast to a (void*) works for me:
>
> No, No... I believe casting funtion pointers to void* pointers is not
> valid C99 code. In short, (void*) is a pointer to 'data',
> void(*)(void) is a pointer to 'code'.
>
> Make sure you pass all the following flags to GCC:
>
>  -Wall -pedantic -std=c99
>
>
>>   __pyx_vtable_7r_jiba1_Norwegian.__pyx_base.describe =
>>
>>                              (void*)__pyx_f_7r_jiba1_9Norwegian_describe;
>>
>>  Again, this is with gcc 4.1 and Py3.0 SVN. Are there any comments on this 
>> one?
>>  What would other compilers say about this?
>
> Well, in this case, the fix is not so easy :-( . I can imagine of a
> hackery that could work, but this requires that you can generate the C
> types for both functions, that is, you can write (here unmangled for
> clarity)
>
> union {
>  void (*fp_base)(struct Parrot*);
>  void (*fp)(struct Norwegian*);
> } describe_Parrot_Norwegian
>
> And then, after introducing a new C scope (that is, beteen braces {}
> ), use the following:
>
> {
>  describe_Parrot_Norwegian tmp;
>  tmp.fp = Norwegian_describe
>  vtable_Parrot.describe = tmp.fp_base;
> }
>
> Vile but cute hackery using type punning ;-) . I do not know of any
> other form that would actually works. The C standard even says that
> the result of that is undefined, but I expect that would not be the
> case in almost all the compilers out there. Check GCC info pages, they
> say that.

I don't think the solution is nearly so complicated.  Can't you just
cast the function to the correct type?

   vtable_Parrot.describe = (void (*)(struct Parrot *))Norwegian_describe;

Carl
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to