From 01125f4b3ced32230e19503ce72a2a9dac63c58d Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 16:13:27 +0330 Subject: globals: a float or f32 global takes a float literal initializer (appendix b.2.7) --- src/compiler/decl.zc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/compiler/decl.zc') diff --git a/src/compiler/decl.zc b/src/compiler/decl.zc index 67aceb1..2c8d13e 100644 --- a/src/compiler/decl.zc +++ b/src/compiler/decl.zc @@ -478,6 +478,9 @@ int gdecl2(int t, int tg, int n) { if (arraytype[0] != TY_ARR || !is_op(s_lb)) serr("a global compound literal needs an array initializer"); else { array_literal(arraytype); vv = xcval; *(a + hdelta) = vv; if (!t) stype[s] = decay(xty); } } + else if (t && isfl(t) && tk == T_FLT) { // float g = 1.5; (appendix b.2.7) + vv = tv; next(); if (t == tf32) vv = rt.zs2f(rt.zf2s(vv)); *(a + hdelta) = vv; // an f32 scalar is a rounded double + } else { vv = cnorm(t, cexpr()); *(a + hdelta) = vv; if (gok) { if (!gty) gty = tint; else if (gty != tint) gok = 0; } -- cgit v1.2.3