2

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

  1. The variable myVar has two elements
  2. The number of bytes that the .f field consumes
  3. 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)?

Paul Grinberg
  • 1,184
  • 14
  • 37

0 Answers0