From 2525a30b5f31e63dc3e7bbb1166ff12de316bc0f Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 13 Apr 2022 00:30:51 +0300 Subject: [PATCH] cgen: [cinit] attr for globals --- vlib/v/gen/c/cgen.v | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 21930b9784..9c5689afb3 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4368,9 +4368,11 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) { } else { '' } - // should the global be initialized now + // should the global be initialized now, not later in `vinit()` + cinit := node.attrs.contains('cinit') should_init := (!g.pref.use_cache && g.pref.build_mode != .build_module) || (g.pref.build_mode == .build_module && g.module_built == node.mod) + || cinit mut attributes := '' if node.attrs.contains('weak') { attributes += 'VWEAK '