3 ms·
I think an exception might be made for a plain "C-like" struct that doesn't initialize members or contain anything except basic types. In the specific example[
by rwmj 3y ago
I think an exception might be made for a plain "C-like" struct that doesn't initialize members or contain anything except basic types. In the specific example[0] the code is actually surrounded by extern "C" { ... } so I suppose that the compiler "knows" this is a plain C struct? (Does extern "C" change parsing rules? I will need to look at what GCC does)
[0] https://gitlab.com/nbdkit/nbdkit/-/blob/cd761c9bf770b23f678fd82f0d1c8d4cce2ed1b5/include/nbdkit-plugin.h#L40 https://gitlab.com/nbdkit/nbdkit/-/blob/cd761c9bf770b23f678f...
- loeg 3y agoC++ compilers know when a structure is POD (plain old data) and could relax initialization order rules for them. I doubt they will.
- flohofwoe 3y agoextern "C" { ... } unfortunately only turns off C++ name mangling for symbols, it doesn't switch the C++ compiler into "C language mode". Such a feature would be incredibly useful though for mixing C and C++ code in the same source file.
- pjmlp 3y agoNaturally, that was always its goal, extern "language" {} produces the same linkage model as language. Even though many only know it with C, Fortran, Pascal and Ada were also common when C++ was gaining adoption. It was never about being a polyglot compiler.