The following:
struct S { }
pragma(msg, s.sizeof);
prints 1. But:
extern (C) struct S { }
pragma(msg, s.sizeof);
prints 0. extern(C++) results in a size of 1.
The size 1 comes from C++, which (correctly) decided that individual objects should have distinct addresses.
This does have the potential to be memory unsafe, and a struct with no data members should be rejected in @safe mode.
Comment #1 by elpenguino+D — 2024-07-10T19:12:53Z
How could this result in memory corruption?
Comment #2 by robert.schadek — 2024-12-13T19:36:24Z