Resource that briefly describe the C and C++ standards - c++

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++.

Related

Is there any C++ coding standard like PSR-1/2

I was searching for C++ coding standard.
I found lots of standards:
Google C++ Style Guide
High Integrity C++ Coding Standard Version 4.0
...
Is there any C++ coding standard like PSR-1/21 that every C++ developer follows?
1) PHP Standard Recommendation. PSR-1: Basic Coding Standard. PSR-2: Coding Style Guide.
Is there any C++ coding standard like PSR-1/2 that every C++ developer follows?
The C++ language standard is made official by the ISO C++ Committee.
The standard comes with iterations and versionings (like c++-11, c++-14, c++-17) that are (mostly) backwards compatible.
That's actually what every C++ developer needs to follow.
If you're actually asking about coding style guides, that's a different thing, and no there aren't any common standards, beyond what's forbidden/discouraged from the c++ standard language.
Well, rethinking the standard style guide wording, there actually are established coding style standards like e.g. Misra C++.
You'll need to consider fulfilling these to get into certain business domains. You may think these are silly, and too restrictive, but still the customer wants you to fulfill these style guides.
It's your choice, and you'll need to estimate your extra efforts and costs (for e.g. investing in a static analysis tool that confirms standard compliance), and put that on the customers bill.
Even though I think the given answers are already good i would like to add the following comment:
There is a rather new project C++ Core Guidelines which tries to do what you are looking for (at least I think so). It is still in an ongoing process but IMHO it is already worth to take a look. There are also some nice talks about these guidelines
CppCon 2015: Bjarne Stroustrup “Writing Good C++14”
and
CppCon 2015: Herb Sutter "Writing Good C++14... By Default"
which explains its main purpose quite nicely. They emphasize static code analysis alot and in my opinion they try to push it alot with these guidelines.
But an important information is
FAQ.6: Have these guidelines been approved by the ISO C++ standards
committee? Do they represent the consensus of the committee?
No. These guidelines are outside the standard. They are intended to
serve the standard, and be maintained as current guidelines about how
to use the current Standard C++ effectively. We aim to keep them in
sync with the standard as that is evolved by the committee.
In the end it means, it is just another set of rules in the sense of the other answers.
No.
If there were a single style guide that everybody followed, why would there be multiple style guides?
For what it's worth, I don't follow anyone else's style guide, and in my opinion neither should you.
Your job may require you to follow a certain guide, but then you wouldn't be asking us which to use.
Notice that I refuse to call these style guides "standards".

when was RAII added to C++

I recently learned about the wonderful memory management technique of RAII, which seems so much cleaner than the new/delete headache I learned in school years ago (I haven't looked at much C++ during the intervening years).
I'm trying to track down when this great technique was added to C++. Was it always there and I just missed the memo? What's the oldest version of the C++ standard which supports RAII?
[UPDATE: OK I realize now why this isn't an ideal SO question -- I have no practical way to verify whether any given answer is correct! Nonetheless I'm still very interested to learn the answer, and I assume the majority opinion will be true.
What I'm hearing is that it's always been there, which I don't doubt is true, but begs the question how come none of my old text books mention it? I just checked Meyers' Effective C++ 2nd edition which I have handy, and will check older texts tonight. Maybe the term was only recently coined, while the technique existed long before?]
When exactly the term "RAII" was coined, I'm not sure. But the technique itself existed in C++ from the moment of its invention, circa 1979.
The first version of the C++ ISO standard was published in 1998.
Any language that has scoped variables with automatic destructor calls is able to do RAII. C++ had this concept from the very beginning as calling destructor when execution leaves scope where variable is declared was in C++ from the very beginning.
Wikipedia's claim that Stroustrup invented RAII is backed by a reference to his book Design and Evolution of C++, published in 1994.
I don't have a copy to check, but it would seem to date from at least this time.

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.

What do I need to know about C++0x? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Where can I learn more about C++0x?
I am fairly familiar with C++03 but I still need to come to terms with C++0x so I would like to read some fairly digestible information on C++0x.
I have looked at the Wikipedia but I am on the look out for something that is more readable. So is there a book or series of blog entries that provide a nice introduction to the matarial?
There is a ton of stuff on this very site - some of the posts include very informative discussion. I would point you to Google but it's going to be more efficient to search in C++0x tagged posts here imo.
Here's a good one to start with, which includes indirection to Stroustrup's own summary. Scott Meyers has presentation materials on the topic here.
Check up on your favourite compiler's support for the new version. Microsoft VC10 support is summarized here. GCC info can be found here.
Official state of the standard for the language is available here. Evolution of the language is in many places tied to ongoing work in Boost. See here for some info on that.
Honestly my preference these days is to look here for 99% of needed info rather than resort to a book.
It's too early for a book. The standard isn't fixed yet.
Now, if you think wikipedia is hard to read, you might try Stroustrup's page about it. However it might seem harder to read to some.
There's a good tutorial on codeproject here for VC++. Even if you aren't using Visual Studio though it's still useful.
Learn whatever feature you would have loved having in C++98 in the first place. For me, it was variadic templates, lambda functions, decltype and other cool stuff.
If you still don't know what to learn first, maybe you should try to understand what issues from the C++98 are adressed. I say this because all the xvalue, move semantics and al stuff is quite heavy to grasp if you don't know what the problems were (and still are btw). This may imply learning some more C++98 first.
Then, you can always browse the Wikipedia article and look at whatever you find cool. Implementors don't provide all the features yet, so you'll look like a 5 year old staring at the front window of a toy store. This is a good reason to behave like one.
I really liked this series of blog posts by the Visual C++ Team Blog:
The Future of the C++ Language
Lambdas, auto, and static_assert: C++0x Features in VC10, Part 1
Rvalue References: C++0x Features in VC10, Part 2
decltype: C++0x Features in VC10, Part 3
I found the Overview of the New C++ (C++0x) book by Scott Meyers to be a good, detailed summary of the main features. It's more of a presentation with very detailed footnotes that an actual book, but it's still an excellent, short read.
I suggest you using the book functionality of Wikipedia to make it more readable/printable. I did the same for the C++0x page.

Where can I find a good quick reference for learning C after years of C++?

I last used C professionally around 1997 IIRC. I've used a lot of C++ since then. Now, I find I need to use some C again.
One thing I'm sure of is that I can't just drop the obvious C++ features (e.g. classes) and expect everything to work. There are various less obvious syntax changes. I just don't remember what they are.
Is there a good reference for making that transition again, but returning to C? If it explains the changes in C99 (and later?) that's even better.
As dirkgently suggests, Harbison and Steele is a good reference, but I don't find it useful to brush up on. To retrain your mind, I have these suggestions:
Reread Kernighan and Ritchie
Optional: read Peter van der Linden's superb Expert C Programming: Deep C Secrets.
Don't forget libraries! Look at P. J. Plauger's book The Standard C Library, or just go to http://dinkumware.com/ (Plauger's company) and browse their excellent documentation of the C99 libraries.
Standard C lacks data-structure libraries. Fortunately there is an excellent, free 3rd-party library that fills several voids: Dave Hanson's C Interfaces and Implementations.
Herbison and Steele: C: A Reference Manual, Fifth Edition may be of help w.r.t C99. Also, read up on the standard, the papers available at open-std.org. And finally, the compiler/tool-chain documentation you are plan to use. The latter puts everything in perspective -- as to how much you need to re-learn.
Not enough but a good starter : C for C++ Programmers
Not a book but read GTK+ source code. It may be fugly but it's got some of the best C source code I've ever read.
C for Programmers, by Leendert Ammeraal, is by far the best thing I have seen along these lines. Unfortunately, it is almost 20 years old, hard to find, and (obviously) not up to date on C99.
Try the following link, I have found it good for reference:
http://www.techbooksforfree.com/ccpp.shtml
Also Sarafi Books or Books24x7, (you have access to both using either ACM or IEEE membership), are excellent references for technical books.
Also, nothing can beat the K&R:
http://www.amazon.com/exec/obidos/ASIN/0131103628
http://www.amazon.com/exec/obidos/ASIN/013089592X
I think the above should give you enough reading material to last for a few weeks and you will emerge as an accomplished C programmer. All the Best. :-)