Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #18254

Re: D'oh! Oh, for lack of a code review.

From Hans-Bernhard Bröker <HBBroeker@t-online.de>
Newsgroups comp.arch.embedded
Subject Re: D'oh! Oh, for lack of a code review.
Date 2014-09-22 19:08 +0200
Message-ID <c8b3c9FivsuU1@mid.dfncis.de> (permalink)
References <hIqdnZIpiN1C3ILJnZ2dnUVZ5rKdnZ2d@giganews.com>

Show all headers | View raw


> I'm not sure why the Gnu compiler bitches if I compare an int to an
> unsigned int,

Because that has partly unspecified results: what is the result of 
comparing -1 to 65535U on a 16-bit twos-complement machine? A 32-bit 
one? And how is the compiler to assume that's what you wanted?

> but doesn't bitch when I compare a boolean to an int

It wouldn't have anything to complain about: that has a perfectly 
well-defined result.

> if (_port.elapsed() > 0 &&
> 	_port.elapsed() < ((_port.clockHz() * 50LL) / 1000000))

Any self-respecting code reviewer still awake at this point of the 
procedure would have rapped you over the knuckles here for using a 
boolean to do what is rather obviously non-boolean work.

But since this is a _design_ error, not a _coding_ mistake, it's a bit 
too much to expect a compiler to warn you about it.  Mind-reading still 
isn't in the requirements spec for a compiler.

But I believe a properly tuned Lint could have caught this (particularly 
if it's been set to enforce MISRA C, which does frown upon such things).

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

D'oh!  Oh, for lack of a code review. Tim Wescott <seemywebsite@myfooter.really> - 2014-09-21 16:23 -0500
  Re: D'oh!  Oh, for lack of a code review. Clifford Heath <no.spam@please.net> - 2014-09-22 09:02 +1000
    Re: D'oh!  Oh, for lack of a code review. Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2014-09-22 00:21 +0000
      Re: D'oh!  Oh, for lack of a code review. Clifford Heath <no.spam@please.net> - 2014-09-22 10:58 +1000
        Re: D'oh! Oh, for lack of a code review. Les Cargill <lcargill99@comcast.com> - 2014-09-21 22:28 -0500
      Re: D'oh!  Oh, for lack of a code review. rickman <gnuarm@gmail.com> - 2014-09-21 22:16 -0400
    Re: D'oh!  Oh, for lack of a code review. Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-09-22 01:28 +0100
      Re: D'oh!  Oh, for lack of a code review. Don Y <this@is.not.me.com> - 2014-09-21 20:16 -0700
        Re: D'oh!  Oh, for lack of a code review. Bruce Varley - 2014-09-22 11:51 +0800
          Re: D'oh!  Oh, for lack of a code review. Don Y <this@is.not.me.com> - 2014-09-21 21:19 -0700
        Re: D'oh!  Oh, for lack of a code review. Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-09-22 22:20 +0100
          Re: D'oh!  Oh, for lack of a code review. Don Y <this@is.not.me.com> - 2014-09-22 16:28 -0700
            Re: D'oh!  Oh, for lack of a code review. rickman <gnuarm@gmail.com> - 2014-09-23 00:43 -0400
        Re: D'oh!  Oh, for lack of a code review. rickman <gnuarm@gmail.com> - 2014-09-22 18:48 -0400
          Re: D'oh!  Oh, for lack of a code review. Don Y <this@is.not.me.com> - 2014-09-22 15:59 -0700
            Re: D'oh!  Oh, for lack of a code review. rickman <gnuarm@gmail.com> - 2014-09-23 00:49 -0400
    Re: D'oh!  Oh, for lack of a code review. Don Y <this@is.not.me.com> - 2014-09-22 16:15 -0700
      Re: D'oh!  Oh, for lack of a code review. Don Y <this@is.not.me.com> - 2014-09-22 16:30 -0700
  Re: D'oh!  Oh, for lack of a code review. David Brown <david.brown@hesbynett.no> - 2014-09-22 10:22 +0200
  Re: D'oh!  Oh, for lack of a code review. Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2014-09-22 19:08 +0200
    Re: D'oh!  Oh, for lack of a code review. Tim Wescott <seemywebsite@myfooter.really> - 2014-09-22 13:59 -0500
      Re: D'oh!  Oh, for lack of a code review. Paul Rubin <no.email@nospam.invalid> - 2014-09-22 12:18 -0700
        Re: D'oh!  Oh, for lack of a code review. tim <tim@seemywebsite.com> - 2014-09-23 00:27 -0500
          Re: D'oh!  Oh, for lack of a code review. Robert Wessel <robertwessel2@yahoo.com> - 2014-09-23 18:35 -0500
      Re: D'oh!  Oh, for lack of a code review. David Brown <david.brown@hesbynett.no> - 2014-09-22 21:26 +0200
  Re: D'oh!  Oh, for lack of a code review. John Speth <johnspeth@yahoo.com> - 2014-09-22 16:24 -0700
    Re: D'oh!  Oh, for lack of a code review. Don Y <this@is.not.me.com> - 2014-09-22 16:34 -0700
    Re: D'oh!  Oh, for lack of a code review. rickman <gnuarm@gmail.com> - 2014-09-23 01:11 -0400

csiph-web