I know that the compiler may add some padding bytes in a struct. But is it possible, when the compiler sees that we never read from a variable inside a struct, that the struct will have a smaller size than the total size of the members?
struct Foo_T foo;
//i never access foo.b, only foo.a
//is it possible that we can end here?
No, this is prohibited by the C standard. In C11, section 18.104.22.168 contains this statement:
15 Within a structure object, the non-bit-field members and the units in which bit-fields reside have addresses that increase in the order in which they are declared. [... ] There may be unnamed padding within a structure object, but not at its beginning.
Removing members of a
struct would violate the requirement that the members have addresses that increase in the order in which they are declared.