michaliskambi / modern-pascal-introduction

Modern Object Pascal Introduction for Programmers, in AsciiDoc
https://castle-engine.io/modern_pascal
157 stars 40 forks source link

Feedback #1

Closed leledumbo closed 8 years ago

leledumbo commented 8 years ago

The logical operators are called and , or , not , xor . Since they also act as bitwise operators, you may need to use parenthesis around some expressions, to avoid confusing the compiler.

The reason is not due to they are also use as bitwise operators (in fac, syntactically both are the same, only the semantics that are different), but due to operator precedence where they're on higher level than relational operators. Thus:

 A = 0 and B <> 0

would be seen as:

((A = (0 and B)) <> 0)

instead of:

((A = 0) and (B <> 0))

by the compiler

michaliskambi commented 8 years ago

Thank you! Something was ringing in my head when writing this, that the operator precedence was the root cause, but I couldn't pinpoint it. I reworked the text around, to explain it correctly. Thanks!