News:

Let's find out together what makes a PIC Tick!

Main Menu

Tern compile error

Started by RGV250, May 25, 2021, 10:37 AM

Previous topic - Next topic

RGV250

hi,
I have used Tern to convert a couple of lines but these lines do not compile and I have no idea what the issue is.
This is the code, both lines fail with Error Line [xxx] :131!(filename)
    dx = Tern(Xend - Xstart >= 0 , Xend - Xstart , Xstart - Xend)
    dy = Tern(Yend - Xstart <= 0 , Yend - Ystart , Ystart - Yend)
I have declared dx & dy, the other variables are declared in the procedure line.

Regards,
Bob


RGV250

Hi,
The issue appears to be the calculation for the result, if I put some fixed values in it compiles
    dx = Tern(Xend - Xstart >= 0 , 1, -1)   
    dy = Tern(Yend - Xstart <= 0 , 1, -1)

Bob

top204

#2
Thanks for noting the anomaly of the compiler not giving the correct error message Bob.

I'll take a look at it.

The Tern function cannot have an expression for the ValueIfTrue  or ValueIfFalse  parameters, it must be a Variable, Constant or Procedure call. See the Parameters section of the Tern function in the manual:

Parameters
Param1 can be any valid variable, constant, expression or procedure call that will be compared to Param2.
Param2 can be any valid variable, constant, expression or procedure call that will be compared to Param1.
Condition is a standard set of comparison characters as found in the If command. They can be <, >, <=, >=, <> or =.
ValueIfTrue can be any valid variable, constant or procedure call that will be loaded into the assignment variable if the comparison between Param1 and Param2 is true.
ValueIfFalse can be any valid variable, constant or procedure call that will be loaded into the assignment variable if the comparison between Param1 and Param2 is false.

RGV250

Hi Les,
That is what is in the Arduino code so I think it will be easier to do If Then Else rather than make a procedure.

Bob

top204

#4
Bob... It is not Arduino code, it is standard C++ using the open source GCC compiler. :-)

Essentially, the Tern function, as with the C and C++, functions are If-Then-Else directives, but in a single entity. I intend to extend the Tern capabilities a little more and add expression compatibility to the IfTrue and IfFalse parameters, but it is not as simple as it sounds because the compiler's original syntax was not designed for them, so it is a battle of wits between my complex parser code and myself. :-)

But, as has been demonstrated many times over the years, the compiler's parser never wins and new features are added, where they should not actually be able to be added. :-)