mirror of
https://github.com/vlang/v.git
synced 2025-09-16 10:57:25 -04:00
parent
856fb8b257
commit
30952cf2bb
@ -6248,7 +6248,13 @@ fn (mut g Gen) const_decl_init_later_msvc_string_fixed_array(mod string, name st
|
|||||||
cname := g.c_const_name(name)
|
cname := g.c_const_name(name)
|
||||||
mut init := strings.new_builder(100)
|
mut init := strings.new_builder(100)
|
||||||
for i, elem_expr in expr.exprs {
|
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_expr.is_fixed {
|
||||||
|
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}'
|
mut def := '${styp} ${cname}'
|
||||||
g.global_const_defs[util.no_dots(name)] = GlobalConstDef{
|
g.global_const_defs[util.no_dots(name)] = GlobalConstDef{
|
||||||
|
32
vlib/v/tests/consts/const_array_fixed_test.v
Normal file
32
vlib/v/tests/consts/const_array_fixed_test.v
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
@[has_globals]
|
||||||
|
module main
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
bar int = 120
|
||||||
|
}
|
||||||
|
|
||||||
|
__global (
|
||||||
|
a Foo
|
||||||
|
)
|
||||||
|
|
||||||
|
const c = [[a.bar]!]!
|
||||||
|
const d = [[a.bar]]!
|
||||||
|
const e = [[a.bar]!]
|
||||||
|
const f = [[[a.bar]!]!]!
|
||||||
|
const g = [a.bar]
|
||||||
|
|
||||||
|
fn test_selector() {
|
||||||
|
assert dump(c == [[a.bar]!]!)
|
||||||
|
assert dump(d == [[a.bar]]!)
|
||||||
|
assert dump(e == [[a.bar]!])
|
||||||
|
assert dump(f == [[[a.bar]!]!]!)
|
||||||
|
assert dump(g == [a.bar])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_literal() {
|
||||||
|
assert dump(c == [[120]!]!)
|
||||||
|
assert dump(d == [[120]]!)
|
||||||
|
assert dump(e == [[120]!])
|
||||||
|
assert dump(f == [[[120]!]!]!)
|
||||||
|
assert dump(g == [120])
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user