[GCC-XML] Problem parsing sdl.h

James Fowler boost_list at openseaconsulting.com
Fri Jan 7 19:21:25 EST 2005


Thomas Heller wrote:

>gccxml (on Windows) chokes on this construct, on the line marked ->: ...
>
>->	void (SDLCALL *filters[10])(struct SDL_AudioCVT *cvt, Uint16 format);
>
>
>As far as I can tell, this is valid C. Isn't it?
>  
>
I think your problem is in SDLCALL.  It probably expands to something
like __stdcall or __cdecl,  Consider the following:

    struct SDL_AudioCVT;
    typedef unsigned short Uint16;
    #define SDLCALL __cdecl

    // these all compile with MSVC 6, MSVC 7.1,  gccxml 0.6.0, and
gccxml 0.70 (recent build from CVS)
    void ( * signal(int, void (*)(int)))(int);
    void ( * signal(int, void (__cdecl *)(int)))(int);
    void (SDLCALL *bar_func_ptr)(int);
    void ( *filters_1[10])(struct SDL_AudioCVT *cvt, Uint16 format);

    // these compile with MSVC 6, MSVC 7.1,  but fail with gccxml 0.6.0,
and gccxml 0.70
    void (SDLCALL *bar_func_ptr_2[10])(int);
    void (SDLCALL *filters_2[10])(struct SDL_AudioCVT *cvt, Uint16 format);
    void (SDLCALL * signal(int, void (SDLCALL *)(int)))(int);


AFAIK, __cdecl and __stdcall are Microsoft-specific extensions.  gcc can
handle it for simple cases, but gets confused with more complicated
declarations, such as arrays of pointers to functions or pointers to
functions returning pointers to functions.  GCCXML works around this for
several common cases by copying and patching common MSVC header files
which would otherwise break the gcc front end.  Quite a clever and
useful trick!  Unfortunately it doesn't help when these problems occur
in header files outside of the standard MSVC distribution.  That's
probably why you're having problems.

As far as fixing it, if you don't actually need to know about ____cdecl
or __stdcall , find out what SDLCALL ends up expanding to and make it go
away for gccxml. For instance, if SDLCALL expands to __cdecl, try adding
in something like

    #ifdef GCCXML_PARSE
    #define __cdecl
    #endif

to sdl.h (or anything  that gets included earlier) and adding
-DGCCXML_PARSE to the command line when invoking gccxml.  This should
make __cdecl disappear, and then that example should parse
successfully.   Unfortunately, simply trying to "clear" __cdecl by using
"gccxml -D__cdecl ..." doesn't seem to do the trick.

Hope that helps!

-  james

james at openseaconsulting.com









More information about the gccxml mailing list