From d739abbb3f11f34e961f3122741936479ae504f9 Mon Sep 17 00:00:00 2001 From: Joe Conigliaro Date: Fri, 18 Feb 2022 00:42:54 +1100 Subject: [PATCH] cgen: move var decl out of loop in global_decl() --- vlib/v/gen/c/cgen.v | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index cd287111a3..413a2d8c86 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4311,6 +4311,9 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) { } else { '' } + // should the global be initialized now + should_init := (!g.pref.use_cache && g.pref.build_mode != .build_module) + || (g.pref.build_mode == .build_module && g.module_built == node.mod) mut attributes := '' if node.attrs.contains('weak') { attributes += 'VWEAK ' @@ -4325,8 +4328,6 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) { } } styp := g.typ(field.typ) - should_init := (!g.pref.use_cache && g.pref.build_mode != .build_module) - || (g.pref.build_mode == .build_module && g.module_built == node.mod) g.definitions.write_string('$visibility_kw$styp $attributes $field.name') if field.has_expr { if field.expr.is_literal() && should_init {