is multiple assignmet line allowed in FB?
similar to below
C:
first->x4 = second->x1 = (first->x3 + second->x2) * 0.5;
I have converted to
FB:
dim c as double = (first->x3 + second->x2) * 0.5
c = first->x4
c = second->x1
wonder is this the better way
c to FB multiple assignmet is single line
Re: c to FB multiple assignmet is single line
No, multiple assignment is not allowed in FreeBASIC, because in BASIC the operator "=" is also used for comparison, so an expression like
will compare B to C, and return -1 if they are equal or 0 if they aren't. So, the value of B is not modified, and the value of A can only be 0 or -1
This applies to other dialects of BASIC, not only to FreeBASIC
in C it's possible to do the double assignment because the operator used for comparison is not "=", but "==" (the operator "=" is used only for assignment, so there is no ambiguity). In BASIC you have to do two separate assignments (don't worry, the resulting compiled code should be identical, with the right optimizations enabled)
Code: Select all
A = B = C
This applies to other dialects of BASIC, not only to FreeBASIC
in C it's possible to do the double assignment because the operator used for comparison is not "=", but "==" (the operator "=" is used only for assignment, so there is no ambiguity). In BASIC you have to do two separate assignments (don't worry, the resulting compiled code should be identical, with the right optimizations enabled)
Re: c to FB multiple assignmet is single line
No, the C code is equivalent to:
Code: Select all
dim c as double = (first->x3 + second->x2) * 0.5
first->x4 = c
second->x1 = c