Shop OBEX P1 Docs P2 Docs Learn Events
spin2cpp incorrect placement of decrement operator — Parallax Forums

spin2cpp incorrect placement of decrement operator

SRLMSRLM Posts: 5,045
edited 2013-06-29 12:43 in Propeller 1
From this source code:
PUB ReadDelta(EncID): DeltaPos
''Read delta position (relative position value since last time read) of EncID.

  DeltaPos := 0 + -(EncID < TotDelta) * -long[Pos][TotEnc+EncID] + (long[Pos][TotEnc+EncID] := long[Pos][EncID])

spin2cpp generates this C++ code (with linebreaks added for readability):
int32_t quadrature_encoder::Readdelta(int32_t Encid)
{
  int32_t Deltapos = 0;
  Deltapos = 
  (0 + (([b]--[/b](Encid < Totdelta)) * (-((int32_t *)Pos)[((*(int32_t *)&dat[196]) + Encid)]))) 
  	+ (((int32_t *)Pos)[((*(int32_t *)&dat[196]) + Encid)] = ((int32_t *)Pos)[Encid]);
  return Deltapos;
}

I get the following error:
quadrature_encoder.cpp:57:41: error: lvalue required as decrement operand

The correct solution is two negation operators or none.

I'm using spin2cpp version 1.04 from the propgcc version alpha_v1_9_0_2042 on Ubuntu 13.04.

Comments

  • ersmithersmith Posts: 6,054
    edited 2013-06-29 11:50
    Thanks for the bug report. I'll fix that. The work-around for now is to split the boolean expression up into pieces (e.g. with a temporary variable).
  • SRLMSRLM Posts: 5,045
    edited 2013-06-29 12:43
    ersmith wrote: »
    Thanks for the bug report. I'll fix that. The work-around for now is to split the boolean expression up into pieces (e.g. with a temporary variable).

    That's better than my solution: change the negation in the spin to a *-1
Sign In or Register to comment.