Jump to content
  • Advertisement
Sign in to follow this  
phil_t

c++ standard?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Ahhh, the dreaded comma operator.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
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.


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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Question: 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!