It's really cool. SWIG doesn't need to know anything about the struct layout you wrap in order to be able to generate the correct code. (You donβt even need to know about all the members that they even contain).
The reason for this is that the generated code is pretty much just data marshaling. In C, you can legally write:
void show_a(const struct foo *instance) { printf("%s", instance->b); }
Regardless of whether foo defined as:
struct foo { double a; char *b; }
or
struct foo { char *b; double a,c; int xyz; }
The only place where packaging / alignment takes place is the creation of new structures. This is handled correctly, but also on the condition that you also do not hide the attribute from the C compiler itself, because the generated C shell code will use the actual definition, and not the pseudo that you specified in the interface file.
This is a bit awkward, but you can see for yourself how it is required when reading through the generated shell.
The general answer is that you can easily relate to SWIG, and in the end everything will work out fine when the C compiler sees the generated code and reconciles it with the real definitions / declarations.
In the specific case, the short answer is: as long as you put only this #define in the .i file, and then only in the place where it will not be passed to your generated module_wrap.c, you are fine.
Flexo source share