cogu/cfile

An example to generate a structure initializer

ayushev opened this issue · 2 comments

Thanks for the work, probably the only one which would work for the my needs!
Is there a way to generate either of the following lines:

typedef struct mystruct {
    int            field_1;
    int            field_2;
} my_struct_t ;

my_struct_t instance = {
    .field_1= 0,
    .field_2= 1
};

or

typedef struct mystruct {
    int            field_1;
    int            field_2;
} my_struct_t ;

my_struct_t instance = { 0, 1 };

Thanks in advance

cogu commented

I tried it myself just now and encountered several issues. I will get back to you once I've made the proper fixes.

cogu commented

@ayushev, sorry for the long delay. I had to make a major redesign of the implementation to accommodate struct initializers.

I just releasded v0.3.2, it has basic support for positional initializers (named elements not yet implemented).
Please look at the updated README for code examples.

Also note that I had to break compatibility with everything before it. Now the declaration element is necessary but gives much better control in how the code is generated.