The first thing you asked yourself is why your application cares if the struct resized. This indicates the fragility of future changes, and your design can be better served, instead allowing the application to work without problems when changing structural changes.
Perhaps you are trying to serialize the data directly and do not want to deal with changes in the format, but in this case you are already attached to one specific representation of the structure in memory. For example, keep the size of one of the built-in change members due to a compiler update or parameters.
But say you really want to do this.
Just wrap the data in the implant and substitute the real structure:
struct SetupData { struct Impl { int var1; double var2; }; Impl impl_; unsigned char pad_[256 - sizeof(Impl)]; };
source share