1
0
forked from alex-eg/sex

spell the least long long as C's LLONG_MIN

-9223372036854775808 reached C as written, where it negates an unsigned
constant, and had no type for inference: it is read as
-9223372036854775807 - 1, which is long long on both sides.
This commit is contained in:
2026-10-27 22:41:06 +03:00
parent 28aaaf637c
commit a2bbb73524
3 changed files with 12 additions and 5 deletions

View File

@@ -1190,7 +1190,10 @@
(emits? (in-fn "(var n (unsigned int) -1u)") "n = -1u;"))
(test-assert "a number too wide for long long is unsigned, and says so"
(emits? (in-fn "(var n (unsigned long long) 0xFFFFFFFFFFFFFFFF)")
"n = 18446744073709551615u;")))
"n = 18446744073709551615u;"))
(test-assert "the least long long is spelled as LLONG_MIN, and typed"
(emits? (in-fn "(var n _ -9223372036854775808)")
"long long n = -9223372036854775807 - 1;")))
;; A define's body was pasted unwalked, and unparenthesised: `cast'
;; stayed a call, and (* x D) regrouped with D's own operator

View File

@@ -1,6 +1,6 @@
(compilation "-- -std=c11 -pedantic-errors")
(input)
(output "c11: 42 43 6 4 6 12 5 0"
(output "c11: 42 43 6 4 6 12 5 0 -9223372036854775808"
"trigraphs: what??! ??= ???( ??/")
(return 0)
@@ -33,6 +33,7 @@
(var origin point #())
(var unit _ (shape/square 1))
(var pair [_ 2] #(#(point : 1 2) #(point : 3 4)))
(var least _ -9223372036854775808)
(fn sides ((s shape)) int
(var n int 0)
@@ -46,8 +47,8 @@
(var k int 1)
(var add-k (closure ((int)) int)
(closure ((v int)) int (k) (return (+ v k))))
(printf "c11: %d %d %d %d %d %d %d %d\n"
(printf "c11: %d %d %d %d %d %d %d %d %lld\n"
(.area p) (add-k (.area p)) (+ (sides (shape/square 1)) (sides (shape/dot)) 2)
(sides unit) (.area corner) (.area [pair 1]) [primes 2] (. origin y))
(sides unit) (.area corner) (.area [pair 1]) [primes 2] (. origin y) least)
(printf "trigraphs: %s\n" "what??! ??= ???( ??/")
(return 0))