10 ms·
Rejuvenating the Microsoft C/C++ Compiler
- pantalaimon 11y ago> The target of the callback could not be found
- MichaelGG 11y agoI guess I must have experienced some of this rewrite. With VC++ in 2015, a piece of code that had a very long if/elseif chain no longer compiled. Parser stack overflow: program too complex. Easy enough fix (break the if/elseif in half) but funny in a way. 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.
- pjmlp 11y ago> 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.
- stephencanon 11y agoAnnex K is optional.
- pjmlp 11y agoHence why it is 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.
- stephencanon 11y agoAFAIK Annex K originated as a Microsoft proposal, so I find it somewhat strange that you're using it as an example of a C feature that Microsoft shouldn't adopt (though I agree that it's a terrible feature that never should have made the cut).
- pjmlp 11y agoYes, as such there is nothing to adopt. It is already there. What I am in favor is Microsoft pushing C aside. C++ provides safer constructs and if one wants to keep on doing unsafe C style coding, it is still there.
- frozenport 11y agoDoes static analysis still choke on Boost or CGAL?
- simfoo 11y agoI hope Microsoft never decides to ditch their compiler and use something existing like Clang. I may have had headaches due to Microsoft incompatibilities before, but having a real alternative (or even three, MinGW still works fine) is great. That said I applaud their decision to fix their compiler architecture problems!
- claudius 11y agoThere is also the Intel compiler (a bit pricy, but comes with enough bells and whistles that for anything performance-related it is easily worth the money). At least in my experience, its code is a couple percent faster than GCC on modern Intel CPUs. Diagnostics are rather horrible, though.
- azakai 11y agoI believe it has switched to use clang as its frontend, though, so it's not a fully independent alternative anymore.
- deleted 11y ago[deleted]
- nickpsecurity 11y agoIt's good for detecting and working around bugs if nothing else. That's one of reasons OpenBSD development uses so many different pieces of hardware.
- exDM69 11y agoThis is excellent news. MSVC is a big pain in the ass for me, as I tend to write C code (not ++ usually) and Microsoft's C compiler is the one with the worst support for language level features (out of widely used compilers). E.g. having to move variables to beginning of block (c89 style) is just miserable. A popular option is to compile C code as C++ inside an "extern C" block to stop name mangling, but this isn't too clean either. 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.
- Ono-Sendai 11y agoMSVC has those things. __popcnt64 __mm_add_ps etc.. or do you mean something else?
- valarauca1 11y ago>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. 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.
- phkahler 11y ago>> Forgive me as I might be wrong but aren't system intrinsics the same in each compiler? >> 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.
- pornel 11y agoThat's great. Please don't forget to finish the C99 implementation! 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.
- userbinator 11y agoVLAs do not absolve you of the need to ensure the buffer is the right size. In fact, they can be worse since at least malloc()'s failure can be determined from its return value. A VLA will just overflow the stack silently: https://www.clarkcox.com/blog/2009/04/07/c99s-vlas-are-evil/ 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.)
- bluecalm 11y agoThe point is that you sometimes want them on the stack and malloc won't do it for you. MSVC has this already though: https://msdn.microsoft.com/en-us/library/wb1s57t5.aspx https://msdn.microsoft.com/en-us/library/wb1s57t5.aspx 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.
- Peaker 11y agoIf you want them on the stack, it's safer to use MAX_SIZE so that you don't blow the stack when some arbitrary input arrives in the future.
- bluecalm 11y ago1)There is sometimes a very slight performance hit as there is more space between arrays and you miss on cache 2)using something which is smaller than MAX_SIZE is never worse unless you write some safety critical software where a bug when you write to unintended but empty location is better than writing randomly somewhere and/or crashing. I prefer the latter in what I am doing (as it's easier to find something is very wrong)
- makecheck 11y agoNow if they can just figure out how to make project files that aren't completely and utterly incompatible with each other when they're only a few years apart.
- jawilson2 11y agoDo you mean backwards compatible? I feel like I have opened VC++6 files in VS2013.
- ygra 11y agoThe last change I'm aware of was around VS2010 when they changed to MSBuild-based project files. Anything since then?
- thwest 11y agoCMake comes with its own drudgery, but I find it better than trying to keep Visual Studio project files in source control.
- shadowmint 11y agoCome guys, just use clang! 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 http://clang.llvm.org/features.html#license). You don't need to rewrite all of these tools. /me shakes head.
- topbanana 11y agoCompetition is good
- mynegation 11y agoHave you ever been supporting a large C++ code base to be compiled both by MS VC++ and gcc (or clang)? It's not too bad, but you are constantly working around minor incompatibilities and different levels of language support, time that could be productively spent elsewhere. 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.
- pjmlp 11y ago> Have you ever been supporting a large C++ code base to be compiled both by MS VC++ and gcc (or clang)? It's not too bad, but you are constantly working around minor incompatibilities and different levels of language support, time that could be productively spent elsewhere. That is what happens to any technology based on standards instead of gold implementation. Lets have one OS, one browser, one compiler, ....
- flohofwoe 11y agoCan't speak for the parent, but all code I work on professionally or for personal projects compiles cleanly on GCC, clang and VC (all in all about 2 million lines of code). I think it is good for code quality to compile on different compilers, since they all catch different bugs through their warnings and static code analyzers. For this I can forgive minor inconviniences like that VC doesn't fully support C++11, or that clang on iOS doesn't support std::thread_local, or (as a random example that I stumbled upon) that the GCC version I am locked to doesn't have full support for variadic templates as lambda arguments, etc... all compilers have their little problems and corner cases, it would be worse to lose one of the big three compilers.
- shmerl 11y agoSo when will they support C99 (I'm not even asking about C11)?
- pjmlp 11y agoThey already do, to the extent required by the ANSI C++ standard.
- shmerl 11y agoI mean C99 standard.
- pjmlp 11y agoPartial C99 support is required by ANSI C++11 and C++14. This is what Microsoft is currently supporting. C++ is now supported on the kernel level. Good luck doing WinRT applications with pure C.
- Ded7xSEoPKYNsDd 11y agoSo in other words, they don't.
- serge2k 11y agoWhen they build a C compiler.
- shmerl 11y agoSo when will they? They had plenty of time.
- AnimalMuppet 11y agoWhen they think they have good commercial reason to do so (and, apparently, not before).
- 11y ago
- lordnacho 11y agoWell I don't know if it's my machine upgrade or the VC++ upgrade, but my C++ code compiles an awful lot faster on VC2015. I also find the IDE tools very responsive and useful. In particular you can now look at the implementation next to the declaration.
- spongo2 11y agowe made a bunch of improvements to build throughput especially for incremental builds. many improvements to our handling of template code as well. -- steve, vc dev mgr
- blinkingled 11y agoInteresting that they mention using clang as the front end for their code generation backend. 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.
- pmelendez 11y ago> "we knew new features such as constexpr were going to need a different approach." 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. https://news.ycombinator.com/item?id=9462644 https://news.ycombinator.com/item?id=9462644
- malkia 11y agoThis was some excellent information from Microsoft themselves. 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 http://www.geoffchappell.com/studies/msvc/cl/index.htm?tx=23