Microsoft C++ Language Reference - c++

Whenever any question is asked, and a reference text is needed, I never see MSDN C++ Language Reference being referred.
I was browsing through it and I personally feel that it is extremely well written.
Is there some specific reason it is not used as often as a standard?
Is it because it contains some VC++ specific features?

I believe it's because those of us referencing a reference reference the actual standard itself.

The answer is fairly simple: The MSDN reference is not authoritative. It tells you how Microsoft's compiler behaves, and yes, it usually happens to coincide with what the standard says. But when someone asks how the C++ language deals with some situation, only one text has any authority: the ISO standard.
So when answering questions about C++, people tend to reference the standard.
If you ask specifically about how MSVC implements it, then MSDN would be a perfectly valid source. But most questions are simply about C++.
Or to put it another way: if MSDN contains a typo, then MSDN is wrong. If the ISO standard contains a typo, then that's how the language is defined.

MS has been pretty good about making clear which parts of the document are MS specific or not, so I agree that the MS references are pretty good (particularly if you're interested in MS extensions).
I generally refer to the standards docs if I'm looking for information about "what's standard" because:
I have them (see Where do I find the current C or C++ standard documents? for links to how to get yours)
they're PDFs which I find easier to search and read than the web-based or Windows Help-based MSDN docs
they're definitive (as far as answering questions about the standard)
The biggest drawback is that I don't have an electronic version of the C90 standard, yet..

Is it because it contains some VC++ specific features?
I think that's the basic reason. For example, it often contains info on C++/CLI, not just C++.
VC++ 2010 reference, I think, is careful in distinguishing which part is in the C++ proper and which part is in the C++/CLI. But to refer to the standard, of course it's better to refer to the standard itself. VC++ documentation refers to the standard quite often, too.

One interesting example: just look at all those __XXX keywords!! (The C++ standard has none)

The C++ Standard defines how the C++ language works, the Microsoft C++ Language Reference defines how Microsoft's implementation of that language works.
So if you want to know what behavior is guaranteed independent of the compiler, The Standard is your guide. Some details and certain corner cases are left to be implementation-defined there and every implementation can define extensions to the language, so if you want to use those MSCV specific properties Microsoft's Language Reference should explain them.
Most SO questions on C++ on don't explicitly ask for a MSVC specific answer that might not be true for other compilers. So referring to The Standard gives an general, compiler independent answer, while the MS Language Reference wouldn't hold much weight for anything else than MSVC.

Related

c++ proposal for new mathematical special functions [duplicate]

When the C++ committee publish a new feature that will be part of the standard library in the next standard of the language, do they also release some source code or some kind of guidance on how to implement that feature?
Let's take unique_ptr as an example. The language committee just defines an interface for that class template and let the compiler vendor implement it as it wants? How exactly does this process of implementation of the standard library features occur?
Can anyone implement parts of the standard library for a platform that doesn't have support for them yet? Let say I would like to implement some cool features of the C++ standard library to use it on a microcontroller environment. How could I do that? Where should I look for information? If I decide to open source my project, can I do that? Will I need to follow exactly what the standard says, or I can write a non-compliant version?
Usually,
every new library feature goes through a proposal.
If the proposal makes it to the C++ committee's Library Evolution Working Group, it goes through a series of iterations (a "tough ground" as I am aware).
It undergoes a series of refinement process as described here
Should it require a (TS) Technical Specification (since C++11), it goes there to be baked. Take for example, the #include <filesystem> was in a Filesystem TS prior to C++17.
One thing I believe the committee likes, is an implementation experience.
More information can be found on the ISOCpp site
Well, as to the implementation:
There are quite a number of "library features" that cannot be implemented purely as a library. they require compiler support. And in these case, compilers provides "intrinsic" that you could hook on to. Take for example, clang provides intrinsics for certain type_traits
Most library features have some implementation experience, mostly from the Boost libraries.
You could actually look into the source code for the default standard library that ships with your compiler:
libc++ for Clang
libstdc++ for GCC
Sadly most of the implementations use a whole bunch of underscores. Mostly because they are reserved for use by the "Standard Library".
Can anyone implement parts of the standard library for a platform that doesn't have support for it yet?
Yes, you can, so far your compiler supports that platform, and the platform or Operating System provides usable API. For example. std::cout, elements of std::ifstream, and so much more requires platform specific support.
Let say I would like to implement some cool features of the C++ standard library to use it on a microcontroller environment. How could I do that?
You can look into the code of others and start from there. We learn from giants. Some Open Source Examples:
ETL
StandardCPlusPlus
uClib++
How could I do that? Where should I look for information?
You could check the paper that introduced the feature into the C++ library. For example, std::optional has a stand-alone implementation here which was used as a reference implementation during the proposal stages.
You could check the standard library, and do a laborious study. :-)
Search the internet. :-)
Or write it from scratch as specified by the standard
Will I need to follow exactly what the standard say or I can write a non-compliant version?
There's is no compulsion to follow what the C++ standard library specifies. That would be your "own" library.
Formally, no. As with all standards out there, C++ Standard sets the rules, and does not gives implementation. However, from the practical standpoint, it is nearly impossible to introduce a new feature into Standard Library without proposed implementation, so you often can find those attached to proposals.
As for your questions on "can you write non-compliant version", you can do whatever you want. Adoption might depend on your compliance, or might not - a super-widely adopted MSVC is known to violate C++ standard.
Typically, a new feature is not standardized, unless the committee has some solid evidence that it can be implemented, and will be useful. This very often consists of a prototype implementation in boost, a GNU library, or one of the commercial compiler vendors.
The standard itself does not contain any implementation guidance - it is purely a specification. The compiler vendors (or their subcontractors) choose how to implement that specification.
In the specific case of unique_ptr, it was adopted into the standard from boost::unique_ptr - and you can still use the latter. If you have a compiler that will compile for your microcontroller, it is almost certain that it will be able to build enough of boost to make unique_ptr work.
There is nothing stopping you from writing a non-conforming implementation (apart from the trivial point that if you sold it as being standards-conforming, and it wasn't you might get your local equivalent of Trading Standards come knocking.)
The committee does not release any reference implementations. In the early days, things got standardized and then the tool developers went away and implemented the standard. This has changed, and now the committee looks for features that have been implemented and tested before standardization.
Also major developments usually don't go directly into the standard. First they become experimental features called a Technical Specification or TS. These TS may then be incorporated into the main standard at a later date.
You are free to write you own implementation of the C++ standard library. Plum Hall has a test suite (commercial, I have no connection, but Plum Hall are very involved with C++ standardization).
I don't see any issue with not being conformant. Almost all implementations have some extensions. Just don't make any false claims, especially if you want to sell your product.
If you're interested in getting involved, this can be done via your 'National Body' (ANSI for the USA, BSI for the UK etc.). The isocpp web site has a section on standardization which would be a good starting place.

C++ standard documentation [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Where do I find the current C or C++ standard documents?
After reading several websites and books, I notice there is a constant reference to a C++ standard. While reading posts on stackoverflow and c++ forums, the communities encourage following this standard. This encouraged me to Google c++ standard to find out in more detail about the language. Is the standard a book? a published document? a mystic spirit that speaks through some seemingly crazed medium? Is there a single source and a final version that people refer to for verification? Several sites and books claim to be based off the standard, but this is not the same as the standard.
So far, I have found recommendations to look at the ISO standard (which seems to be mostly incomplete drafts) and the GNU c++ documentation at http://gcc.gnu.org/onlinedocs/libstdc++/. I have briefly used these to try to answer some of the questions that come to mind, but I want to make sure these are the proper references to use when answering questions (my own or others) and that I do so according to the proper standard and not something based on the standard (there is a difference).
Just to note:
For me, 99% of all my programming will be done in a Linux environment so there may (or may not be) a different standard for different operating systems
There is a single version of standard. There is no difference between systems( it is one standard). You have to pay go get full version of the standard ( even for PDF file). Everyone is using:
https://github.com/cplusplus/draft [EDITED TO THE NEWEST VERSION]
for free, because it is draft version and it is free. There are some different between draft and released one.
If you want to get a copy of the standard, you can buy it for a small fee from ISO, which is how they fund themselves.
However, if you simply follow the last draft of C++11, which is currently the latest C++ standard, and will remain to be for some time, you will never notice a difference against the released standard.
It is a similar story with POSIX, a standard used for UNIX-like APIs on that family of operating systems. In that case you would want to go here.
However, while a perfect understanding of C++ is highly desirable whatever you do, it may well be that your portability needs will make POSIX somewhat irrelevant to you; either you might only need Linux compatibility, or you might restrict yourself to APIs (such as the standard C++ library or other portable libraries) that will support you even on non-POSIX operating systems.

Resource that briefly describe the C and C++ standards

After having an answer here wrong, because I wasn't up to date on the C standard, I started to look for some place that gives a description of whats in the C and C++ standards.
I do not want the complete standards, of which I found links in Where do I find the current C or C++ standard documents?, or intimate technical discussions. Instead I would like something that briefly describes the standard, with references to the actual standard if I want to check it more thoroughly, and maybe saying which standard the feature was introduced in.
Is there such a resource available?
EDIT: A little background to the question: I have been programming C for over 20 years now, and when I learnt it not much was standardized. And what was in the official standard was not widely implemented. Through the years I have become good enough C programmer that my friends and colleges come to me for help when they have problems.
However, when I learned C I was told that things like memory layout for multi-dimensional arrays was implementation specific, and when I saw a question about that subject I said that it wasn't standardized only to be told I was wrong. But even knowing this, I have a hard time finding any place saying that it's in the standard, and it's even harder to find in which standard it was first introduced.
If there was some place saying "Memory layout of multi-dimensional arrays was standardized in C9x, in section Y of the standard document" It would have been easy to find and give this to the person asking the question. I am not intrested in what the actual layout is, just that it has been standardized, and where to look if I really want a definitive answer about it.
This of course goes for other things. Like knowing that header file "<yyy.h>" is mandated by standard "C90", and where in the standard I should look for the rationale and contents of it. It is very difficult to find these things when they are spread out, having it collected in one place would make it much easier to find.
Anything that's not the standard will either be not definitive, or be simplified in such a way as to be far less than useful. And anything definitive or really useful will basically be the standard.
I know of no resource that covers every section of the C standard (or even a sizable number of them) in a simplified way and I would doubt its usefulness. You generally have a specific issue you need solved and, in that case, you would search for that specific issue - the vast majority of people don't need the standard, especially when they have a resource like SO at their fingertips.
If you're a language implementer or enjoy examining the dark corners of the language in excruciating detail, then yes, get the standard, it's invaluable. If you're just using the language day-to-day (even as an expert), you can get by without it, with just a bit of googling (a).
(a) Make sure one of the search terms is site:stackoverflow.com :-)
I found http://en.cppreference.com/w/cpp is now becoming pretty good! (always much more complete)
There is so much material in the standard there is just no way to briefly describe it. I don't think your question is really answerable as written. If you want a reference for the standard library though, Josuttis' book http://www.amazon.com/Standard-Library-Tutorial-Reference/dp/0201379260/ref=sr_1_1?ie=UTF8&qid=1320994652&sr=8-1 is always a fantastic reference.
I'm guessing you already are familiar with the older standards and want to brush up on the newer less-used stuff.
Here is a good read for C99. It covers changes and has notes to the actual standard. Also some stuff on C++ in there.
Wikipedia is great for C++11. Great for basics, but doesn't go into full detail.
If you fully understand the language then you can generally infer the standard. For strange corner-cases you're going to have to refer to the standard.
I think some of the other people answering this question are right: one seldom needs the ultimately authoritative ISO standard document, unless you are writing a compiler or something like that. For me, I find that the main books on the two languages by the language creators are sufficient for almost all my needs. They are:
The C Programming Language by Brian Kernighan and Dennis Ritchie
The C++ Programming Language by Bjarne Stroustrup
Look for the latest editions of each, although a quick search on Amazon shows neither updated for the latest incarnations of the languages (C99 and C++11). You might need to supplement with online sources, or perhaps look at A C Primer Plus and Professional C++.

Looking for C/C++ language and standard libraries specifications [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Where do I find the current C or C++ standard documents?
I have several C books, and one of them, C by Discovery, explains the language very well. But so far I don't seem to have been able to find the full C/C++ language and library standards and lists of functions, types, etc., in whole detail.
Where is exactly a full standard for C99 and also the older, supposedly more commonly used and accepted, C language standards, the C++ language standards, and their libraries?
Is there some of them I must pay for, or should I just follow what Wikipedia and documentation like that of GCC cite?
Where else should I go to download or get them fully?
The Wikipedia article C99 has a link at the bottom to a draft of the C99 language specification. It is a draft because the final published version you have to pay for. But the draft is basically accurate, so it's a good reference. This is an extremely long specification of the entire language including the library, but possibly not what you are after. To just see the standard library, simply consult the man pages. Consult the Wikipedia article C standard library for a list and summary of the various functions.
For C++, the same deal. The Wikipedia article C++ has links to various drafts of the complete specification, notably the most recent draft of C++ from 2010 (the old C++, before C++0x comes into effect). The Wikipedia article C++0x has similar links to drafts of the soon-to-be-named C++ 2011 standard. But if you are just looking for a reference on the standard library, you can't go past cplusplus.com's reference section, which includes full documentation for the C library (in C++ mode), the IO library, and the STL (containers and other misc utilities). That's what I use as a day-to-day library reference.
The best online copy of C99 I've found is here:
http://busybox.net/~landley/c99-draft.html
If you want the actual standard, I don't think you can just download it. I believe you have to buy a copy from the American National Standards Institute. The GCC documents don't provide all the detail you need for the base language that GCC extended.

How should the C++ standard be used

I have this classic question of how should the C++ Standard (I mean the actual official document of the finalized ones) e.g. C++98, C++03 be used to learn and teach C++. My idea is only from the point of view of an average C++ user and not from the point of view of the language lawyers or someone who wishes to be in the Standards committee, compiler writers and so on.
Here are my personal thoughts:
a) It is aweful place to start learning C++. Books like "C++ in a Nutshell", "The C++ programming Language" etc do a very good job on that front while closely aligning with the Standard.
b) One needs to revert to the Standard only when
a compiler gives a behavior which is not consistent with what the common books say or,
a certain behavior is inconsistent across compilers e.g. GCC, VS, Comeau etc. I understand the fact that these compilers could be inconsistent is in very few cases / dark corners of the language e.g. templates/exception handling etc. However one really comes to know about the possible different compiler behaviors only when either one is porting and/or migrating to a different environment or when there is a compiler upgrade e.g.
if a concept is poorly explained / not explained in the books at hand e.g. if it is a really advanced concept
Any thoughts/ideas/recommendation on this?
The C++ language standard would be an absolutely terrible place to start learning the language. It is dense, obtuse, and really long. Often the information you are looking for is spread across seven different clauses or hidden in a half of a sentence in a clause completely unrelated to where you think it should be (or worse, a behavior is specified in the sentence you ignored because you didn't think it was relevant).
It does have its uses, of course. To name a few,
If you think you've found a bug in a compiler, it's often necessary to refer to the standard to make sure you aren't just misunderstanding what the specified behavior is.
If you find behavior that is inconsistent between compilers, it's handy to be able to look up which is correct (or which is more correct), though often you'll need to write workarounds regardless.
If you want to know why things are the way they are, it is often a good reference: you can see how different features of the language are related and understand how they interact. Things aren't always clear, of course, but they often are. There are a lot of condensed examples and notes demonstrating and explaining the normative text.
If you reference the C++ standard in a post on Stack Overflow, you get more a lot more upvotes. :-)
It's very interesting to learn about the language. It's one thing to write code and stumble through getting things to compile and run. It's another thing altogether to go and try to understand the language as a whole and understand why you have to do things a certain way.
The standard should be used to ensure portability of code.
When writing basic c++ code you shouldn't need to refer to the standards, but when using templates or advanced use of the STL, reference to the standard is essential to maintain compatibility with more than one compiler, and forward compatibility with future versions.
I use g++ to compile my C++ programs and there I use the option -std=c++0x (earlier, -std=c++98) to make sure that my code is always standard compliant. If I get any warning or error regarding standard compliance, I research on that to educate myself and fix my code.