operator precedence

Top  Previous  Next

What is translated > Operators > operator precedence

 

In complex expressions, rules of precedence determine the order in which operations are performed. Delphi has four levels:

 

 

level

operators

1.

@, not

2.

*, /, div, mod, and, shl, shr, as

3.

+, -, or, xor

4.

=, <>, <, >, <=, >=, in, is

 

The first level is the highest precedence and the fourth level is the lowest. The  equivalent operators are spread in C++ on 11 levels.

 

level

operators

1.

(address) & ! ~             // dereference *, unarary + -

2.

* / %

3.

+ -

4.

<< >>

5.

< > <= >=

6.

== !=

7.

&

8.

^

9.

|

10.

&&

11.

||

 

 

To reproduce the order in which expressions are performed in Delphi appropriate parenthesis must be inserted in C++.

 

For example, while in Delphi the And and Or operators have a higher priority than the equality operators, in C++ equality operators are evaluated first. So at the translation of the following condition:

 

if attr And flag = flag then

 

according parenthesis are set in the C++ output:

 

if( ( attr & flag ) == flag )

 

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content