[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Help with C API



On Monday 27 May 2002 04:56, Riccardo Trocca wrote:
> I've found a partial answer to my problem! <br>
> I was using C++ files. I mean that I asked SWIG to generate C++ files,  in
> this way I could use default parameters in the function definition  (that
> was inlined). <br>
> Switching to C&nbsp; file generation (and losing default parameters, sigh
> I was able
> to succesfully compile everything. <br>
> Anyway I don't think it is a good thing, what if I want to write some 
> extension using C++? 

I'm familiar with C/C++ compatibility issues.  From your description, it 
appears that what you're running into is that C++ requires a void* pointer to 
be cast back to the appropriate type before it's used.  So in pygame.h
all of the macros (such as import_pygame_base) which do
   void** localptr = (void*)PyCObject_AsVoidPtr(c_api);
would need to be changed to 
   void** localptr = (void**)PyCObject_AsVoidPtr(c_api);
for them to work in C++.

Making code that's valid and compatible in both C and C++ isn't hard if you 
work at it a bit.  There are link-time as well as compile-time issues. The 
trick of putting in your C++ code
     extern "C" {
     #include "some_C_header_file.h"
     };
only works if you're lucky.  The header file normally needs a little special 
care in order to support both languages.
									-- Scott Turner

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org