Suggestion to enhance code readability
Mark Rosenthal
mbr at aoa.UUCP
Fri Aug 23 09:21:32 AEST 1985
Although our site has been receiving articles for the past few months,
articles posted to the net have not been getting distributed until recently.
The following is a reposting of an article I sent out quite some time ago.
I believe it never made it to the net at large. Apologies if you have seen
this before.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Alexis Dimitriadis (alexis @ reed) writes:
> Expressions like "while (var++) ;" introduce problems that take
> (bitter) experience before they can be handily detected, even if the
> reader is familiar with the semantics of the expression. That is the
> real reason it takes a seasoned C programmer to debug seasoned C code.
Since every simple C statement ends with a ";", it is easy to misread
the ";" in the above as a terminator for the while statement, rather
than a terminator for a null statement controlled by the while. Placing
the ";" on the same line as the while makes this misinterpretation very
likely. That is why I came up with the following (equivalent) construction,
which I have been using for several years. I believe it enhances readability.
But then, I have weird tastes.
while (var++)
{ }
--
Mark of the Valley of Roses
...!{decvax,linus,ima,ihnp4}!bbncca!aoa!mbr
More information about the Comp.lang.c
mailing list