Code: Select all
function ShowNum( iNum as long ) as long
print iNum
return 50
end function
ShowNum(5)+ShowNum(10)
sleep
it prints 10 and 55 ...
if storing the result instead of discarding then it shows the right ones... 5 and 10.
Code: Select all
function ShowNum( iNum as long ) as long
print iNum
return 50
end function
ShowNum(5)+ShowNum(10)
sleep
Code: Select all
ShowNum((5)+ShowNum(10))
Code: Select all
dim i as integer
i=ShowNum(5)+ShowNum(10)
GO language: ShowNum(5) + ShowNum(10) evaluated but not used
The next token of first ShowNum should be open paren, Why the parser need add another ()?TeeEmCee wrote: ↑Jun 15, 2022 2:52 That's because it's parsed asI believe this is actually intentional behaviour, though I'm not so happy with it. It causes other problems too (and is a backcompat break to change). In nearly any other programming language, the function call operator () always has higher precedence than math operators such as +, but statements as opposed to expressions parse differently in FB.Code: Select all
ShowNum((5)+ShowNum(10))
Code: Select all
dim p as long
p+p
Code: Select all
function foo as long
return 1
end function
foo+foo
Yes I understand that. Sorry to call it a bug. Quirk is more appropriate! I definitely maintain that calling two subs and adding them together is probably not a good practice anyway, even in languages that don't exhibit this quirk, like C.
gcc/tcc also have the warning but its disabled by default... "has no effect" from D sounds weird as there is an effect by the call to the function but yes... guess on D it being an error is... mehKuan Hsu wrote: ↑Jun 15, 2022 13:21GO language: ShowNum(5) + ShowNum(10) evaluated but not used
D language: Error: `ShowNum(5) + ShowNum(10)` has no effect
gcc 8.1: pass, output is 5 and 10
tcc 0.9.24: pass, output is 5 and 10
The next token of first ShowNum should be open paren, Why the parser need add another ()?TeeEmCee wrote: ↑Jun 15, 2022 2:52 That's because it's parsed asI believe this is actually intentional behaviour, though I'm not so happy with it. It causes other problems too (and is a backcompat break to change). In nearly any other programming language, the function call operator () always has higher precedence than math operators such as +, but statements as opposed to expressions parse differently in FB.Code: Select all
ShowNum((5)+ShowNum(10))