strange or inconsistent parsing of multiple return values
|
|
Bugzilla Link |
925 |
Created on |
Mar 01, 2012 13:11 |
Resolution |
WORKSFORME |
Resolved on |
Apr 21, 2012 18:46 |
Version |
1.00beta |
OS |
Linux |
Architecture |
PC |
Extended Description
The multiple-return value parsing feels strange in several respects.
First it requires parentheses. C doesn't require parentheses for
a return value. One can write:
return value;
But in SAC this doesn't work for multiple return values:
ABORT: line 11 file: testcomma.sac
ABORT: syntax error at pos 13: ',`
ABORT: return a, b;
ABORT: ^
This code works when it is changed to "return (a, b);".
Second the multiple return value cannot be used
in combination with the ternary conditional operator:
ABORT: line 13 file: testcomma.sac
ABORT: syntax error at pos 26: ',`
ABORT: return ((k <= 1) ? (a, b) : (c, d));
ABORT: ^
To make this code work one has to revert to tedious code like:
e = (k <= 1) ? a : c;
f = (k <= 1) ? b : d;
return (e, f);