does any one know the rules followed by SF Compiler when evaluating an expression with mixed type operands?
For example ?
Code: Select all
Dim i, j as byte
dim w, z as word
w = i * j + z
Regards
Moderators: David Barker, Jerry Messina
Code: Select all
Dim i, j as byte
dim w, z as word
w = i * j + z
Code: Select all
Dim i, j as byte
dim w, z as word
temp_u16 = i * j ' temp_u16 is a word
w = temp_u16 + z
It all works pretty well when using integral data types, but if you're going to be mixing floats and integers you might have to be more careful.Are type conversions dependent on the lValue type or does the compiler evaluate the full expression (doing any type conversion depending on the terms forming the expression) and then convert final result to the type of the lvalue (if conversion is legal of course)?
yes I think that the compiler handles the expressions like ISO pascal do, i.e it works and adjust types (type promotion) depending on the terms directly arround actual operator.Jerry Messina wrote:
For example, 'byte * byte * float' produces different code than 'float * byte * byte',
ends up being:byte * byte => result1 (byte)
result1(byte) * float => promotion of result1 to float before doing multiplication