I have some C code which has static initializers with values that are derived from macros. These intializers are essentially my code's external API. I am looking for a way to autogenerate documentation for my code so that the initialization values would be easily visible.
For example, below is a very simplified C program #include
typedef unsigned int u32;
#define Q 5
#define W 7
#define BaseNum 0x1000
#define CalculateNumber(x) (BaseNum + x)
#define SomeOtherCalc(x,y) (x<<y)
typedef struct
{
u32 a;
} foo;
typedef struct
{
foo f;
} bar;
static const bar myVar[] =
{
{
.f = {
.a = CalculateNumber(SomeOtherCalc(Q,W))*sizeof(u32),
},
},
{
.f = {
.a = CalculateNumber(SomeOtherCalc(W,Q))*sizeof(u32),
},
},
};
void main(void){}
Given that program, I would like to get autogenerated documentation which says that
- The variable myVar has two elements
- The number of bytes that the .f field consumes
- The value of the .f.a field for each element in myVar
I can get some of that information directly from GCC using gcc -E, but it doesn't completely resolve the value of .f.a nor the sizeof() into a number. Any ideas on how I can get what I'm looking for (preferably without using Doxygen)?