I made some changes to a C codebase so that it could compile under G++. Seems to be working, with some annoyances and the hack of -fpermissive -fshort-wchar
.
Out of curiosity I compared the stripped -O2
size of the GCC-built executable before my changes, and the G++-built executable after my changes. The "after" was 32 bytes larger (on a 500K-ish binary). I was pleasantly surprised it was so close, but idly wondered why if the optimizer is that consistent it wouldn't be 100% consistent? But maybe something about adding that overload for strchr caused it.
Not important enough to me to worry about. But then I decided to a C build with GCC taking my C++ compatibility changes into account. That stripped -O2
executable was 4096 bytes bigger than the C build prior to my changes.
Does anyone have intuition on why these three sizes would happen this way, and why it would be such a "round" number? The C++ changes were basically all things that should be optimized out, whether in C or C++. Basically:
introduction of opaque typing so that functions previously defined in the interface as taking void* would name-mangle consistently. introduced some cast assignments to locals via macro of the opaque type to a local of the proper internal type
elimination of a few instances of old-style C function header definition
modification of linkage to "extern" for some global constants that hadn't specified linkage before, temporarily tolerating keeping the assignments in the headers but hoping to argue against that
changing some signed chars to unsigned chars, and some unsigned longs to unsigned int (but never vice versa)
If anyone has a good intuition for this optimization case, then it would save me the time of backing out each set of related changes individually to see how they affect the size...!