views:

364

answers:

6

Hey,

I was wondering if, and to what degree, does Microsoft's Visual C++ compiler conform to the current C (C90/C99) and C++ (ISO/IEC 14882:2003) standards. Unfortunately I'm only able to find partial information on the subject, I may be looking at all the wrong places.

Any pointers to related resources are much appreciated. Thanks in advance.

Edit: Since is looks like this is a most touchy subject, I'd be content with a yes/no answer on whether MSVC wholly conforms to C90...I've come to the understanding that this is not the case for C99 (naturally), and I still have no clue about C++..

Edit2: Thanks to everyone for their answers. I've accepted Mr. Rushakov's answer but upvoted all relevant answers, which were all helpful.

+7  A: 

Perhaps MSDN's Nonstandard Behavior page for Visual C++ will enlighten you? Make sure you look at the version you're most interested in (the box on the right-hand side).

Since MSDN's links change all the time (and who knows why), here's the main content from the page on VS2008, so when the link breaks and someone comes across this answer, they can Google and find the correct page:

Nonstandard Behavior

The following topics are some of the known places where the Visual C++ implementation of C++ does not agree with the C++ standard. The section numbers refer to section numbers in the C++ standard.

Mark Rushakoff
That was indeed helpful, wrt C++.
Michael Foukarakis
+1  A: 

Visual C++ 2k3, 2k5, and 2k8, conform to C89, and C++98.

Some additional features are cherry-picked from C99, and there are a few enhancements on top of C++98.

Matt Joiner
That’s the point, though: it *doesn’t* fully conform to C++98 – although admittedly standard compliance has gone up considerably since the dark ages of VC6.
Konrad Rudolph
ouch, tbh, i couldn't care less about c++ conformance, and I use C++ everyday. however lack of c99 really hurts.
Matt Joiner
+2  A: 

My pet peeves, which most programmers find unimportant but which I personally find to hurt readability a lot, is that VC++ is unable to compile the following C++ code:

bool result = true and not false;

… because VC++ doesn’t recognize and, or and not (along with the rest of ISO 646) as valid tokens.

Clarification: The standard mentions the treatment of the above tokens in §2.12, marks them as reserved in §2.11 and defines an equivalence mapping for them in §2.5 to the more conventional operator representations (e.g. and corresponds to &&). It isn’t clear why they get a special status next to the other keywords. Even more confusingly, appendix C2.2 suddenly calls them “keywords”. Still, the standard is absolutely clear about their treatment and semantics. VC simply doesn’t implement these paragraphs (unless you specify the /Za flag during compilation).

Konrad Rudolph
Works for me. VS2005, /Za
MSalters
i always wondered where those keywords were hiding, and why i couldn't use them! thx! http://msdn.microsoft.com/en-us/library/34h23df8.aspx
Matt Joiner
Keywords? These have never been keywords. These are macros defined in <iso646.h>. I don't know how VC can be "unable" to recognize a macro, if you haven't forgot to include the appropriate header.
AndreyT
AndreyT: no, you are definitely mistaken; they are keywords, they are defined in the standard (look it up!) and they do *not* require inclusion of `<ciso646>` in order to work on a fully compliant compiler.
Konrad Rudolph
@Konrad Rudolph: No, the standard doesn't list any of them as keywords. The complete table of keywords is available in 2.11/1 and none of these tokens are in the table. Section 2.11 does have another table with these alternative tokens, but it explicitly states that these are just alternative tokens and that they are reserved. Nothing in 2.11 refers to these tokens as "keywords".
AndreyT
@Konrad Rudolph: The funny part is that a couple of years ago I participated in this argument on the "keywords" side in `comp.lang.c++`. I believed these were keywords since Appendix C said so (C.2.2.2). To which I was told that Appendix C is not normative, so it doesn't really matter what it says.
AndreyT
@AndreyT: My bad, they aren’t *keywords*. However, §2.12 defines them as preprocessor tokens which are converted into tokens in translation phase 7. Thus they *are* part of the valid punctuation tokens. *More to the point*, §2.5 is normative and defines the alternative token mappings from preprocessor tokens to operator tokens. These include digraphs and all the tokens from §2.11/table 4. … The VC compiler (notwithstanding the `/Za` flag) doesn’t properly implement §2.5 and §2.12.
Konrad Rudolph
(cont’d) Section C2.2.2 simply expands on this. It’s not “normative” in that it doesn’t define anything new, it merely makes the distinction clearer, i.e. it explains that, since the tokens from 2.11/table 4 are already defined, they no longer need to be (and hence shall not be) represented as macros in `<ciso464>`. That’s all that C2.2.2 means. Compare this to C2.2.1 which contains a very similar explanation concerning `wchar_t`. Likewise, `wchar_t` *is* a keyword in the C++ standard. In conclusion: appendix C2.2 is simply a *summary* of all the changes. …
Konrad Rudolph
(cont’d) In conclusion: while C2.2 isn’t normative, §§2.5 and 2.12 certainly are. (That C2.2 calls these tokens “keywords” just adds to the confusion.) – I will edit my original answer now to make this clearer.
Konrad Rudolph
Well, props for digging through all that. So after all that, can I call them keywords? I gather not. However I also gather that it should not be necessary to #include <ciso646> either.
Matt Joiner
+1  A: 

Standards compliance for C and C++ has been rather poor for VS. Things began changing with 2005 and is getting better. VS2010 is what I am really looking at with quite a lot of features from C++0x. Most of the time though, I end up Googling with the following keywords:

  • msdn ANSI C conformance
  • msdn ISO C++ conformance

etc. when I really really need to figure out why something doesn't work as defined.

dirkgently
+2  A: 

I don't use VS 2008 yet, so I can only speak for VS 2005.

It doesn't support C99. Support for C89/90 has always been good in VC and I'm not aware of any non-compliance issues with it.

C++98 support has a number of issues, some of them are documented by MS as known issues and some are plain bugs. I made a blog entry to use as a "notebook" for various VS 2005 C++ bugs I encounter in practice. If you wish, you can take a look here, although this list is probably far from being complete

AndreyT
+1  A: 

__try is marked as an extension

Arabcoder