#stupidcompilertricks — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #stupidcompilertricks, aggregated by home.social.
-
I was thinking about FORTRAN's arithmetic-if statement
`if (expr) linenumber1, linenumber2, linenumber3`I think the closest you could get to that in a non-FORTRAN language still in use would be in C with GCC's labels-as-values extension:
`goto *(result = (expr)) < 0 ? &&label1 : !result ? &&label2 : &&label3;`If the original FORTRAN code didn't go spaghetti (and if `expr` is an integer expression), then you could do it with a C switch-case statement (using GCC's or C2Y's case-ranges):
```
switch (expr) {
case INT_MIN ... -1:
...
case 0:
...
case 1 ... INT_MAX:
...
}
```
or Java's classic switch-case:
`switch (Integer.signum(expression)) { // use cases -1, 0, 1`If there's no fallthrough, then you could use Java's "enhanced" switch-case or Python's match-case:
```
match expr:
case k if k < 0:
...
case k if k == 0:
...
case k if k > 0:
...
```https://godbolt.org/z/dx9dr6oKT
My point? I don't think there is one.
#StupidCompilerTricks