[GCC-XML] pragmas, preprocessor

Thomas Heller theller at python.net
Wed Sep 22 08:57:33 EDT 2004


Brad King <brad.king at kitware.com> writes:

> Thomas Heller wrote:
>
>> I'm very impressed by gccxml - it's able to parse the windows header
>> files without any problem!
>
> Thanks.  It is actually only able to do that because the installer
> copies some of the windows header files from your compiler's
> installation to its own install location and then patches them to make
> them parsable.

Sounds cool ;-).

>> I'm trying to use it to create Python wrappers for the structures and
>> functions declared in the header files for the ctypes project.  The
>> problem I have now is that MSVC uses pragmas to specify the packing
>> alignment for structure and union members.  Is it somehow possible to
>> get these pragmas?
>
> I do not think this is possible through GCC-XML directly.  However,
> I'd be interested in knowing why you need this to generate wrappers.
> I bet there is another solution such as setting up the generated
> wrapper code to detect these values at compile time when needed.

I need to know this because there is no C compilation step afterwards -
the python wrappers can directly be used.  See the ctypes tutorial at
<http://starship.python.net/crew/theller/ctypes/tutorial.html>, if you
are interested.  It's a kind of C data types emulator.

So far I only see this solution: the parser and generator that parses
the XML output from gccxml, and generates the Python code, must have anb
additional step, where short C programs are created, executed and
compiled, which try to find out the packing of the structure, and
finally spit out the Python wrapper code.  Would be a pity, though, if
there weren't another solution.

[5 minutes later]

Hm, I just found out that '#pragma pack' even seems to work with gcc
(Suse linux, gcc 3.3.1) on a C program.  Would it be possible (I'd even
try to work on a patch) to expose either the current packing for
structures, or expose field offsets of structure members in the xml
output?

Thanks,

Thomas




More information about the gccxml mailing list