[fpc-devel] weird syntax

Bram Kuijvenhoven kuifwaremailinglists at xs4all.nl
Tue Dec 11 18:17:23 CET 2007


Michael Schnell wrote:
> Andrew Haines wrote:
>> Is it possible to make this work:
>>
>> if X > 3 or < 10 then ...
>>
>> of course it would be shorthand for: if (X>3) or (X<10) then....
>>   
> The "or" operator is stronger than the "<" operator by definition. This 
> can't be changed.
> In C we have a logical or ("||") and a binary or ("|"), as there is no 
> boolean type. In Delphi language there is only one operator "or", as the 
> type defines the makeup of the operation. While this is nice, it 
> prevents the "<" operator from being stronger that "or", as the "or" 
> might be bitwise.

In C the operators &, |, && and || *all* have lower precedence than ==, !=, <, >, <= and >=. (As a consequence, in C you probably want to use parenthesis in an expression like (mask & 0xF38A) == 0xF080.)

Though I also don't like the parenthesis in (X>3) or (X<10), I think it is not really a good plan to change the precedence of operators in FPC, since it encourages writing code that is not compatible with Pascal standards.

Regards,

Bram



More information about the fpc-devel mailing list