c++ standard?

This topic is 3985 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Does anyone know where I can find an online version of the c++ standard? I'm trying to figure out the exact behaviour of the middle expression in a for-loop. Consider:
for (a; b,c; d)
{
// stuff
}


From my tests, it looks like b is ignored, and the result of c is used to determine if the loop continues. Is b executed at all, and the result thrown away? I've googled around a bit, but haven't been able to find anything that goes into enough detail to explain something like this.

Share on other sites

What "b, c" does is it evaluates both b and c then returns c. In other words, yes, b is executed and the result is thrown away.

Share on other sites
Thanks! (That's kind of what I figured...) Dreaded indeed...

Share on other sites
The comma operator can be useful if b has side effects - the only place I've seen it used frequently is in for loops with more than one index:

for(int i = 0, j = 10; i < j; ++i, --j){}

Probably best avoided.

Share on other sites
As for the original question, you can't find a legal copy of the C++ standard online. The final draft is available in several places ( example), but the actual standard needs to be purchased. You can get a copy from your national standards body. For the United States, that would be ANSI. Copies can be usually obtained in both electronic format (PDF) and hard copy. However the version published by Wiley is probably the cheapest dead tree edition.

Share on other sites
Quote:
 Original post by SiCraneAs for the original question, you can't find a legal copy of the C++ standard online. The final draft is available in several places ( example), but the actual standard needs to be purchased. You can get a copy from your national standards body. For the United States, that would be ANSI. Copies can be usually obtained in both electronic format (PDF) and hard copy. However the version published by Wiley is probably the cheapest dead tree edition.

Question: why do the relevant organizations hold themselves free to do this? Does a similar situation exist for any other widely used language? It doesn't, AFAIK, for Python, or even for Java. (Sun supposedly has a bad reputation when it comes to this kind of thing, nearly as bad as Microsoft, yet you can download the JLS directly from them. Well, not exactly the same as the book, but AFAICT as close as they can manage legally - certainly a lot closer than a draft version.)

Share on other sites
The good thing is that the final draft is supposed to have the same text than the final version. I can't be sure of that (can't extract the text from the PDFs I have), but that can be quite logical.

BTW the final draft of the standard (as well as the final draft of the TR1 and the current draft of the next iteration of the labguage) are available from the WG21 web site as well.

Share on other sites
The final draft isn't exactly the same as the standard. There are some word changes (such as "should" becoming "shall"), but the meaning seems essentially the same.

@Zahlman: I don't understand what the question means. "hold themselves free"?

Share on other sites
Quote:
 Original post by ZahlmanQuestion: why do the relevant organizations hold themselves free to do this?

Because the relevant organizations (by which I mean ISO and ANSI) concern themselves with standardization only (it's not a side hobby -- it's part of their name in both cases), and that's their main way of making the money necessary to continue to support their activities.

• 17
• 11
• 15
• 9
• 49
• Forum Statistics

• Total Topics
631393
• Total Posts
2999774
×