Looking for a tool that takes a C structure as input and outputs a structure with minimal size.
For example, given an initial structure with only 3 members
struct Book {
char title[50];
char author[25];
int book_id;
};
there are 6 permutations
struct Book1 {
char title[50];
char author[25];
int book_id;
};
struct Book2 {
char title[50];
int book_id;
char author[25];
};
struct Book3 {
char author[25];
char title[50];
int book_id;
};
struct Book4 {
char author[25];
int book_id;
char title[50];
};
struct Book5 {
int book_id;
char author[25];
char title[50];
};
struct Book6 {
int book_id;
char title[50];
char author[25];
};
The output shows that 80 bytes is the minimal size.
Book1 = 80
Book2 = 84
Book3 = 80
Book4 = 84
Book5 = 80
Book6 = 80
Several projects I work on contain structures with 10+ members (3628800 permutations) and are continually appended with new members by coders not familiar with structure packing complexities.
Question
Is it possible to have a tool to refactor the structure into the best minimal size?