Pascal Viandier wrote:
The following sample code does not compile properly with GPC (20050331).
Program Real; Var R1, R2 : Real; Begin  R1 := 4.21; R2 := R1 * -1.0; WriteLn(R2); End.
GPC output: real.pas:6: error: syntax error before `-'
The problem occurs with negative integer constants and any operator (+-*/) as well.
Strange enough, if I modify the code for: R1 := 4.21; R2 := -1.0; R2 := R1 * R2;
Or even for: R2 := -1.0 * R1;
The code compiles and the output is as expected. It looks like one can assign a negative constant to a variable but cannot use it as an operand if it is on the right side. This is not a problem for multiplying but for the other operators... Could this be a bug?
No, it's a simple parentheses. The correct Pascal syntax is:
R1 * (-1.0)
Borland Pascal has a different (non-standard) precedence for unary minus, so this works there. GPC does this with `{$borland-pascal}' (not by default, as it may cause non-standard results in other cases).
Frank