A cast of a bitwise expression loses its parentheses #62

Closed
opened 2026-10-08 18:43:17 +02:00 by alex-eg · 1 comment
Owner

(cast (c-bit-or xn 1) float) emits (float)xn | 1, which C reads as
((float)xn) | 1: a compile error here, but with an integer target
type it would silently cast only xn. Arithmetic operands are
parenthesized; bitwise ones aren't. With the two entries below, that
makes three places where operator precedence leaks into the output.
In this project they have cost more time than every other entry put
together, mostly through (if ...) in arithmetic, which keeps coming
back because it reads so naturally.


Found with sexc dfafe8b while building vs-map-viewer (from its Sex-field-notes.org).

`(cast (c-bit-or xn 1) float)` emits `(float)xn | 1`, which C reads as `((float)xn) | 1`: a compile error here, but with an integer target type it would silently cast only `xn`. Arithmetic operands are parenthesized; bitwise ones aren't. With the two entries below, that makes three places where operator precedence leaks into the output. In this project they have cost more time than every other entry put together, mostly through `(if ...)` in arithmetic, which keeps coming back because it reads so naturally. --- Found with sexc `dfafe8b` while building vs-map-viewer (from its `Sex-field-notes.org`).
alex-eg added the bug label 2026-10-08 18:43:17 +02:00
Author
Owner

Fixed by 8bc27cb.

Fixed by 8bc27cb.
Sign in to join this conversation.