Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 30, 2024
1 parent 04aba8f commit 4ccc3ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -6247,7 +6247,13 @@ fn (mut g Gen) const_decl_init_later_msvc_string_fixed_array(mod string, name st
cname := g.c_const_name(name)
mut init := strings.new_builder(100)
for i, elem_expr in expr.exprs {
init.writeln(g.expr_string_surround('\t${cname}[${i}] = ', elem_expr, ';'))
if elem_expr is ast.ArrayInit {
elem_typ := g.typ(elem_expr.typ)
init.writeln(g.expr_string_surround('\tmemcpy(${cname}[${i}], (${elem_typ})',
elem_expr, ', sizeof(${elem_typ}));'))
} else {
init.writeln(g.expr_string_surround('\t${cname}[${i}] = ', elem_expr, ';'))
}
}
mut def := '${styp} ${cname}'
g.global_const_defs[util.no_dots(name)] = GlobalConstDef{
Expand Down
16 changes: 16 additions & 0 deletions vlib/v/tests/consts/const_array_fixed_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@[has_globals]
module main

struct Foo {
bar int = 120
}

__global (
a Foo
)

const c = [[a.bar]!]!

fn test_main() {
dump(c == [[120]!]!)
}

0 comments on commit 4ccc3ca

Please sign in to comment.