Shop OBEX P1 Docs P2 Docs Learn Events
spin2cpp Byte and ~ Error — Parallax Forums

spin2cpp Byte and ~ Error

SRLMSRLM Posts: 5,045
edited 2013-07-17 10:47 in Propeller 1
When converting the read_pulse_widths from the Eddie project I get the following error:
read_pulse_widths.cpp:40:11: warning: promoted ~unsigned is always non-zero [-Wsign-compare]

It looks like the problem code is
uint8_t	Cog;
int32_t read_pulse_widths::Stop(void)
{
  if (~Cog) {
    cogstop(Cog);
  }
  return 0;
}

And the spin source:
VAR

  byte                cog

PUB Stop                        'Stop the currently running cog, if any

  if !cog
    cogstop(cog)

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-17 10:41
    It's actually a warning that says that since Cog is a uint8_t "if (~Cog)" will always succeed. This is because the Cog will be promoted to a uint32_t, and since the upper bits are zero, the complement will always be non-zero.

    It appears that there's an error in the original Spin code. The normal practice is to set Cog to the return value of cognew plus 1, and to test Cog for a non-zero value when doing a cogstop. The logic in the current Spin code is incorrect.
  • SRLMSRLM Posts: 5,045
    edited 2013-07-17 10:47
    Dave Hein wrote: »
    It's actually a warning that says that since Cog is a uint8_t "if (~Cog)" will always succeed. This is because the Cog will be promoted to a uint32_t, and since the upper bits are zero, the complement will always be non-zero.

    It appears that there's an error in the original Spin code. The normal practice is to set Cog to the return value of cognew plus 1, and to test Cog for a non-zero value when doing a cogstop. The logic in the current Spin code is incorrect.

    Oops. You're right: the spin code does have an error. I'm making a list of the bugs in Eddie so I'll be sure to add that one. Thanks for catching it.
Sign In or Register to comment.