C/C++ idioms, as the name implies, are coding procedures or conventions in the C or C++ languages, whose meaning is not directly identifiable at first glance. That is, unless you are familiar with the idiom from previous experience, in which case you should immediately know what is going on without even mentally parsing the code. The good ones are so often used that they almost seem to become part of the language itself.

For instance, real programmers would see for(;;) and immediately recognize that an infinite loop follows. (Hopefully you put in some sort of escape procedure. If not, your cow orkers have my permission to slice off your slavering tongue and feed it to wild monkeys). To the uninitiated, that rather cryptic expression may cause overwhelming confusion. Another idiom used for looping is while(i--) for countdowns.

One of my favorite examples of idiomatic blocks is the swapping of two integers without using a buffer variable:
x^=y;
y^=x;
x^=y;

And, of course, both C and C++ have their own idioms which are exclusive of each other.

Log in or register to write something here or to contact authors.