[fpc-devel] Types and Casts handling in FreePascal Expressions

Pocket MicroTechnics Support octal at pocketmt.com
Wed Apr 20 10:01:54 CEST 2011


Hello,
I have just a little question about expressions and types/cast management
in FreePascal.

if I have a mixed expression with:
i, j, n : byte
k   : word

n := i + k - j;

in this case, how does the compiler handle this situation?
it evaluated
Add i , k   ->  result
and then
sub result, j

how the types are handled?
does the compiler cast i to a word, add it (word addition) to k, and cast
j to word, do substraction and then the result is tranformed back to a
Byte to do the assignment?

What I mean, does the compiler handle types locally by casting at each
node, and force the cast at assignment node?
or does it do like C compiler, i.e. check the LValue at left of the 
assignement, take its type, and cast each BinOp node to this type
systematically (which in the previous example means that k is casted to
byte and only byte operations are done).

Regards and thank you for your time :)






More information about the fpc-devel mailing list