diff options
| author | 2026-10-14 16:13:27 +0330 | |
|---|---|---|
| committer | 2026-10-14 16:13:27 +0330 | |
| commit | 01125f4b3ced32230e19503ce72a2a9dac63c58d (patch) | |
| tree | 9b48b00217333961bc9380a926eb5f8e7a687ba2 /src/compiler/decl.zc | |
| parent | fndef: a prototype after a definition in the same module keeps the definition... (diff) | |
globals: a float or f32 global takes a float literal initializer (appendix b.2.7)
Diffstat (limited to 'src/compiler/decl.zc')
| -rw-r--r-- | src/compiler/decl.zc | 3 |
1 files changed, 3 insertions, 0 deletions
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; } |
