Microsoft to C99 Developers: Use ISO C++
infoq.com
infoq.com
Just install ICC (the Intel compiler). It hooks into Visual Studio, is a better compiler for both C and C++ than MSVC, works really well, produces really fast binaries, and does all its magic in the backend. Nothing changes for you, the developer.
It's both free for non-commercial development and paid for commercial dev, which makes perfect sense to me.
Their excuse is that they can't guarantee they would work identically on AMD and so resort to much slower un-pipelined code. It's like Ferrari testing a Porsche and only using 1st gear because they can't be sure that other gears would perform in the same way
It doesn't play nicely with MSVC++, which is a big problem because most third party libraries on Windows are built with MSVC++ and expect projects using them to be built with MSVC++.
And the only debugger usable with Mingw is raw GDB. The debug format it uses isn't compatible with MSVC++'s debugger. Sure, GDB is very powerful, but it's very difficult to use compared to MSVC++, XCode, and even the GDB front ends on Linux.
Also, there's not much of a build system with Mingw unless you're happy with hand rolled Makefiles or using MSYS. I've never had much luck running MSYS. Maybe it's improved lately, but downloading an arbitrary open source library and trying to run "./configure && make" in MSYS is a crap shoot. Unless the library author has taken steps to make it work it probably won't.
As somebody else said, if you're porting code from Linux that uses a lot of non-standard GCC extensions, GNU Make and autotools then Mingw is tolerable as long as you can develop entirely on Linux and only use MingW for porting and testing.
There are some limited cases where it's actually pretty good, though. For example, the open source version of Qt ships its own version of GCC, GNU Make, etc, and hides the details behind their Qt Creator IDE. If you're using Qt with minimal dependencies outside of Qt, it's a nice setup. Also, GHC and the Ruby "Windows dev kit" do the same thing for compiling/building language extensions.
If you are a Mac or Linux weenie who just wants to port something over to Windows sure, no problem, use MinGW. But good luck getting any Visual Studio devs to rely on what is, for all intents and purposes, a second rate Win32 toolchain.
C99 and C11 look like mutants compared to C89. Too many bad design decisions made by a group of people who weren't involved with the initial standardization. They even did the very thing the guy who _invented_ the language explicitly told their predecessors in no uncertain terms not to do, and reintroduced noalias pointers into the language [1].
`noalias` was fundamentally broken, which is why it was never adopted by the committee. Instead, `restrict` was standardized, but `restrict` does not suffer from the problem that Ritchie highlights in the post you linked to.
It's also worth noting that C99 fixed some significant oversights in the C90 standard; C99 fully specified integer division for example (C90 left the behavior implementation-defined for negative arguments).
Read the link to dmr's comment again. His argument wasn't so much that noalias was specified incorrectly, it was that the whole idea of adding any kind of alias specifier to the language is against the spirit of C. I agree, and apparently so did the C++ committee. If you want to write FORTRAN, write a FORTRAN spec. Leave C alone.
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.
long long foo; /* bigger ints on 32-bit platforms */
uint32_t bar; /* stdint.h, integers of specific bit width */
int array[n]; /* length-n array, where n is a variable */
for (int i = 0; i < n; i++) /* loop-local variable */
Also, the safer stdio functions like snprintf. - declarations mixed with statements
- declarations in `for` constructs
- hexadecimal floating-point literals and conversion specifiers
- the strtoxx( ) conversion routines
- the restrict qualifier
- the expanded math library
- designated initializers
- extended integer types
- compound literals
- // comments
- VLAs
- complex support
Note that some of these features are still not present in C++11.C11 features that I have used in the past few months:
- CMPLX macros
- anonymous structures and unions
- <stdalign.h> struct { struct y y; bool flag; } = { .flag = true };In general, C feels well-suited to be the language that (almost) every other language can talk to; C++ just doesn't fit that role so well.
I'm not sure how else you think C++ could handle its goals without the name mangling: overloading and compatibility with C's linker system. If you have two overloaded "foo" functions you need to somehow designated them as separate linker symbols.
C has similar problems of its own: like what's the calling convention for the exported symbol? Do I push the arguments on the stack, and who cleans up? Do some arguments go into registered? Where does the return value go? What's the layout of a struct? All things are platform, compiler and compiler configuration dependent.
What other languages, that compile to object files or shared objects, that support the level of OO features etc. that C++ has, have a well-defined ABI?
Plus, sometimes having fewer features is itself a feature. I would say that this is especially true when comparing the slim, minimal design of C with the "everything and the kitchen sink" approach of C++. Not that C++ is never useful in its own right, but that doesn't mean its appropriateness for a given task is always greater than or equal to that of C.
This mostly means it's incompatible with C even in the parts of the language both of them share. Completely valid and idiomatic C code will therefore not always compile if you use a C++ compiler.
- Visual Studio is a great IDE but more importantly it's what MS devs are used to. It's harder to attract good MS developers if you don't support Visual Studio
- Binary compatibility issues between stuff compiled with gcc/mingw and stuff compiled with VS (??? Someone chime in here if I'm wrong)
- Gcc/mingw setup on Windows is perceived as more complex than installing VS
If you aren't using C++, everything should work fine. I've been using C binaries from VS and mingw together without problems :)
Mixing C++ binaries from different compilers is much trickier
I usually compile outside of IDE (from command line / Far Manager) with custom build script and use MSVC only as a debugger: it has nice feature of opening EXE file as a project workspace.
We're stuck with MSVC until gcc and its Windows ports will have a decent GUI debugger.
There is nothing you can do in MSVC that you can't do more slowly in a less-obvious manner in either gdb or eclipse.
Anecdata FTL, I guess. Note that the CDT of long ago was absolute trash. If you haven't tried it in the past couple of years, get a recent version of Eclipse and try again. It's really a good tool.
Well, I can't blame them for wanting to use their tools of choice, but as a developer wanting his work to be compatible with the most popular platform, it's an unfortunate situation.
void func(int size) {
int array[size];
In the words of the noted philospher and business expert - "Well duh"