Re:Microsoft to C99 Developers: Use ISO C++
by chocolatebunny on Monday May 07, 2012 @02:37PM
(#3940315)
What's the C++ alternative to designated initializers?
Re:Microsoft to C99 Developers: Use ISO C++
by stephencanon on Monday May 07, 2012 @02:55PM
(#3940424)
Constructors, I would assume, but that's not a very attractive alternative in my opinion.
With C++11, you can use constexpr constructors to guarantee that they run at compile-time and end up as flat data in the .data/.rodata section instead of run-time static initialization. Or so I'm told by the C++11 people I asked about it.
C99 has some very hard-to-replicate features; most notably designated initializers. Without them, you cannot statically initialize any union member except the first. This is a significant problem for me.
C99 is mostly supported by every C compiler I am aware of except MSVC, so it would be portable if not for Microsoft.
> Even if you don't really use any language features unique to C++, you would still get some safer library functions and better portability than you would if you limited yourself to the C99 standard.
C++ is not available in the Linux kernel, it mangles names, and it's tricky to be disciplined enough to write in a C++ subset without letting C++ features creep in, especially on a multi-person project. Once you let C++ features creep in you can inadvertently end up with runtime static initializers, type_info symbols, exception unwinding code and debugging symbols, etc.
My current compromise is to compile as C99 everywhere except on MSVC, where I will compile as C++ and use C++ alternatives to features like designated initializers.