203 points · by ingve · 11y ago · 134 comments
I'd also like to have compatibility of some language extension features, such as built-in functions and attributes. In particular, CPU-agnostic intrinsics for common instructions like atomics, popcount or count leading zeros as well SIMD arithmetic would be great.
My favorite C language extension is SIMD vector arithmetic with infix operators. You can get really pretty and portable (!) vector math code written in Clang and GCC using vector extensions, but again, it's not available in MSVC.
For most of my current projects, I have no intent of supporting the (current) Microsoft C compiler. It's not worth the effort.
Main omissions I've noticed: printf isn't quite the same (no 'z' modifier, the 'n' forms are noticeably inferior), no VLAs.Also, standard library isn't POSIX (which is not an omission but a lot of C code assumes POSIX so you'll probably end up having to deal with this).
I'm surprised you mention intrinsics, since VC++ has a wide selection - https://msdn.microsoft.com/en-us/library/hh977022.aspx - and I'd expect, though without proof, the differences between many of those available on both VC++ and gcc/clang to be something you could work around with #define or, failing that, a small inline function (and cross your fingers).
Aside from VLAs, which is annoying, you can work around most of these with wrapper functions and #defines. So I've been pleased enough with the latest VC++. As a long time programmer for multiple platforms, I can put up with a certain amount of deprivation, and having to put in a bit of effort doesn't bother me (all that much). But I've noticed a tendency for people to sometimes assume that "multiple platforms" means "ten different types of gcc+POSIX+fork+pthreads". I'm sure that even shiny new C99-friendly VC++ won't make them happy.
This. Unfortunate, but some even seem to think C99 support automatically means POSIX and then start complaining a platform isn't compatible if it doesn't handle what they thought was portable code..
Having done multiple platform C development across Aix, HP-UX, Solaris, GNU/Linux and Windows in the first .com wave, as well as, having some embedded knowledge, it is always interesting that for some people only gcc and now clang exist.
As for C99, Microsoft is pretty clear that are only supporting what is required by the C++ standard.
Here's an older article - http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-librar...
(I've seen more recent ones, but I can't find an example to hand)
Since VS2013 there has been partial C99 support and as such this is not needed anymore, finally.
Forgive me as I might be wrong but aren't system intrinsics the same in each compiler? I was under this impression as I wrote a lot of SSE2/3 C99 code for the GCC using MSVC++ documentation it compiles/runs without an issue. (This also before finding the MMX/SSE/AVX docs that intel has which are beautiful).
I mean the function/variable type names (for x86_64 at least) are the same for Clang/ICC/GCC/MSVC.
>> I mean the function/variable type names (for x86_64 at least) are the same for Clang/ICC/GCC/MSVC.
Yes, all those compilers support the same names for x86_64. Then a different set for ARM NEON, and a different set for PPC AltiVec. What GCC has done is implement another set of names that can be used across all those hardware architectures. To clarify the difference, you can choose - do you want to move your code between different compilers, or different hardware but always with GCC.
I actually find this style clearer since all the variables are accounted for at the beginning and it helps when looking for them (and associated comments, if any). You can always open a new block when you need a new set of variables. Do you happen to have started with a more dynamic language which didn't require variables to be declared? That was the case I've seen with most other programmers who preferred creating (often very many) variables only at the point of use.
I find the style easier to read as you can instantly see what variables will be operated on, what arrays filled etc. It's also quite important for me to know how much stuff is allocated in given block so I don't blow out the stack and having all the things at the top makes it easier to think about. It's probably about being used to it but I found the code with mixed declarations and logic to be inelegant and more difficult to understand.
Beginning of block variables are generally always worse than as late as possible variables.
The article isn't very clear, but I would guess backward compatibility is going to trump adding new features as far as the C compiler goes.
I wouldn't mind getting proved wrong, but the article mentions a lot of C++ features they're working on, and doesn't mention an C features they're working on.
That said I applaud their decision to fix their compiler architecture problems!
For tiny values I really like being able to use int arr[runtime_size]; rather than risking buffer overflows with int arr[MAX_SIZE] or arr = malloc(size * sizeof(oops)); — and MSVC is the last compiler that still doesn't support that.
https://www.clarkcox.com/blog/2009/04/07/c99s-vlas-are-evil/
Edit: to expand on this point, if you really need to keep all that data in memory at once, it's often better to just malloc() a buffer of the appropriate size and reuse it, reallocating if it should be bigger. (Obviously, do not forget to free() it eventually.)
so I really don't think there is any good will there. It seems someone in the management is set on "C++ is the future, C is obsolete" view, at least that's the impression I've got from the press releases about it.
The point is that a lot of code uses them and that makes porting it a pain. I mean, they spend so much resources to implement all the new toys in C++ which just introduce the new way of doing the same thing but to actually implement something which is used in real world code, which they already almost have (_alloca) is sometimes a problem because it's "unsafe". No one sane can actually believe that explantion.
A. They make stack allocation much more dynamic, harder to reason about its bounds, and arbitrary inputs may blow the stack later.
B. They make sizeof a dynamic thing! sizeof can no longer always be constant folded and can even cause side effects!
I hope they'll be able to continue to keep up C support as well as C++. It'd been so nice having C99 in MSVC, as cross-platform projects can now adopt C99 features.
I hope that they only keep it as much as required by the ANSI C++ standard.
Annex K was a joke.
Not only has the standards comitte not done anything serious about preventing bounds overflows, they made it optional.
Sizes still aren't guaranteed to be correct for the string/buffer.
No portable C code can rely on its presence.
[1] http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-librar...
It does not actually allow you to write compliant C99 and compile it.
A would like to see a similar article for OpenWatcom v2.
Geoff Chappell has been uncovering various various Microsoft compiler and linker (plus other bintools) hidden command-line options and environments (like _CL, _CL_, and _LINK, _LINK_) - http://www.geoffchappell.com/studies/msvc/cl/index.htm?tx=23
Stephan Lavavej (STL) also mentioned this a while ago. It is nice to see they have been working on this so maybe MSVC can catch up with new standard features faster from now on.
Glad that they're finally undertaking this, it'll take cross platform C/C++ code a long way if there's more standardization across all major compilers.
It's state of the art, all the tooling already exists, and its under a very permission license (http://clang.llvm.org/features.html#license).
You don't need to rewrite all of these tools.
/me shakes head.
Now, I know that's quibbling, but this really isn't: What do you think is less work and less risk for Microsoft: throwing enough resources at MVCC to make it better, or throwing enough resources at Clang to make it so that Windows and Office compile on it without introducing regressions?
Does the officially released version support OpenMP by now? A few weeks ago at least I still failed at installing that properly from official sources. There seems to be an OpenMP-in-clang project going on, but it was far from obvious what had to go where. So about this “state of the art”…
MSVC still only supports OpenMP 2.0.
The code works correctly when compiled with GCC so that can't be an issue. I am launching OpenMP threads from a Windows thread (not the main one) so maybe that's the issue (MinGW packages had problems with it forever and it's pretty tough to find one without this bug present).
./clang++ --version
clang version 3.8.0 (trunk 246030)
Target: x86_64-unknown-linux-gnu
Thread model: posix
does not support OpenMP to my knowledge.I agree that competition is good, I'd much rather prefer compilers competing on the speed, quality of their optimization, static analysis, supported platforms - something that does not give me much of a headache.
Having said that, I acknowledge that MS compiler team made great progress in the recent year catching up on C++ standards, compatibility, and compilation speed.
That is what happens to any technology based on standards instead of gold implementation.
Lets have one OS, one browser, one compiler, ....
>>the speed, quality of their optimization, static analysis, supported platforms
if the C++ committee wasn't that "prolific" about adding yet new ways to do the same thing to the language. It sucks a lot of resources to implement that monstrosity and every 3 years or so there is a new set of toys to play with.