On Fri, Nov 15, 2002 at 04:39:13PM -0800, Mark Wilden wrote:
>> if ((len = StrLen (Data.Field2)) > 0) RecordSize += len + 1;
>
> Since StrLen can't return < 0
Well, you and I know that (assuming no bugs in the implementation), but
does the compiler know that? Oddly enough, it depends on the SDK you're
using. In SDKs earlier than 3.5, it returns unsigned (effectively UInt16);
in the 3.5 and 4.0 SDKs it returns signed (Int16); in the 5.0 SDK it has
reverted to returning unsigned (UInt16).
I believe the change in the 3.5 SDK was made because it was believed
that it would reduce spurious signed/unsigned comparison warnings with
some compilers.
I've (asked for but) seen no explanation of the 5.0 change. Presumably
the intent was to return to matching reality and the standard strlen()
function (which returns size_t, which is unsigned), but it remains to
be seen whether people's programs will be disrupted by the return of
spurious warnings.
> how about
>
> if ((len = StrLen (Data.Field2)))
> RecordSize += len + 1;
>
> (The extra parens are sometimes the easiest way to turn off the usual
> warning about assignment within conditional).
IMHO the *clearest* way to avoid that usual warning is to add an extra
explicit test, even if it is not strictly necessary. If you disagree,
that's fine (and IMHO it's not a particularly interesting topic to
discuss except down the pub), but I'm glad we don't collaborate on code
reviews or maintain each other's code :-). If you think dropping that
extra test has any effect whatsoever on the efficiency of the generated
code, then you need to spend some time playing with a disassembler.
John
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/