Sign In
Forgot Password?
Sign In | | Create Account

C++ - for loops

Colin Walls

Colin Walls

Posted Jan 24, 2011

I am [mostly] a fan of using C++ for embedded applications. I believe its use needs care and I have written about this before. Broadly, I feel that it offers many simple improvements over C and appropriate use of object oriented techniques can be very beneficial. Today I want to talk about the place of C++ as a "better C language". There are numerous syntactical improvements that can be leveraged to make code just a little more readable and maintainable. However, there are some minor "quirks" that can catch the unwary programmer. Who would have thought that you could go wrong with a plain old for loop? ...

Development Tools

More Blog Posts

About Colin Walls Follow on Twitter

Colin WallsI have over twenty-five years experience in the electronics industry, largely dedicated to embedded software. A frequent presenter at conferences and seminars and author of numerous technical articles and two books on embedded software, I am a member of the marketing team of the Mentor Graphics Embedded Systems Division, and am based in the UK. Away from work, I have a wide range of interests including photography and trying to point my two daughters in the right direction in life. Learn more about Colin, including his go-to karaoke song and the best parts of being British: Visit The Colin Walls Blog

More Posts by Colin Walls

Comments 3

Post a Comment
But according to the C++ standard, the scope of i only extends to the end of for statement. So if the compiler reports an error about that, it's a bug of the compiler.

Jie Zhang
11:28 AM Jan 24, 2011

It is good news that this functionality has been standardized. However, deviations from language standards are not uncommon in C++ compilers.

Colin Walls
11:32 AM Jan 24, 2011

This has been in the standard since at least 1998 (ISO/IEC 14882:1998 section 6.5.3). If I remember correctly, prior to 1998 this was not the case. So, to run into this problem today, you would either have to be using a really old compiler, or it is simply a bug.

Mark Johnstone
6:12 PM Jan 26, 2011

Add Your Comment

Please complete the following information to comment or sign in.

(Your email will not be published)



Online Chat