q: code that generates printf() statement to dump C struct contents



Hi,

I am sure, others also have had a need for this.
I am examining a C API for the first time, writing small test programs
and dumping the contents of C structs.
What I am looking for is a code fragment or tool that will take a C
struct declaration as input, maybe even complete header files with
typedefs and the like and generates a dump_struct function that takes
a pointer to the actual struct as input and then dumps or displays the
structs' contents via printf(), leaving the comments from the header
file intact.

any hints?
Joachim

generated code would be something like:
void dump_struct_xx( struct xx *p )
{
printf("struct xx {\n\\
int xy=%d; /* comment from the header file */\n\\
}", p->xy );
}


.



Relevant Pages

  • [PATCH] fix various kernel-doc in header files
    ... Fix a number of kernel-doc entries for header files in ... notation and use @var notation. ... struct hlist_node *new) ... timer_pending - is a timer pending? ...
    (Linux-Kernel)
  • Segmentation Fault in my program
    ... I am facing problem while I am on the way of organizing the ... Actually I had to create the header files. ... // the struct is declared as global. ... In the Label class, when I try to pass this value to the local variable ...
    (comp.lang.c)
  • Re: [ patch 6/7] drivers/serial/jsm: new serial device driver
    ... >Don't put header files in header files if you can help it. ... Since some tools in Digi company need these new ioctls to access device ... +struct digi_dinfo { ...
    (Linux-Kernel)
  • [PATCH] Factor out common MODULE_INFO content from module*.h files.
    ... and moduleparam.h header files, factor out the common MODULE_INFO ... #define THIS_MODULE ((struct module *)0) ...
    (Linux-Kernel)
  • Re: Did you try ReactOS?
    ... On Jan 8, 6:43 pm, Aleksey Bragin ... It's not really legal to fully *copy-paste* those header files, ... typedef UNALIGNED struct _TA_ADDRESS { ... So, if I were to rewrite these public headers in another laguage, say ...
    (microsoft.public.development.device.drivers)