Bad syntax

| 1 Comment
Came across this one in a piece of C code.
(conditionflag & STATUSBIT) ?
        (KdPrint(xxxx)) : 0;
Edited [ 2005-08-04, 19:42 Pete ] There was no code making use of the result of the ?: operation.
This piece of code is terrible from both a readability and functionality perspective. If the return type of the function is changed to a void, then there won't be a valid left hand side for the evaluation to function correctly, from a readability perspective the developer split the code over two lines, which made it ripe for the more legible form of:
if (conditionflag & STATUSBIT)
        (KdPrint(xxxx));
Ah well, you can't boss everyone around all of the time I suppose.

1 Comment

The old version returns the value of KdPrint(), though. The new version throws it away.

About this Entry

This page contains a single entry by Pete Shanahan published on August 3, 2005 12:54 PM.

Desktop search and code was the previous entry in this blog.

Quote from a page is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.