mirror of
https://github.com/vlang/v.git
synced 2025-09-16 07:52:32 +03:00
parent
ce95787215
commit
1b812f6bdf
6 changed files with 40 additions and 0 deletions
|
@ -7353,6 +7353,11 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
|
||||||
} else {
|
} else {
|
||||||
'{'
|
'{'
|
||||||
}
|
}
|
||||||
|
$if windows {
|
||||||
|
if !typ.has_flag(.shared_f) && g.inside_global_decl {
|
||||||
|
init_str = '(${g.typ(typ)}){'
|
||||||
|
}
|
||||||
|
}
|
||||||
if sym.language in [.c, .v] {
|
if sym.language in [.c, .v] {
|
||||||
for field in info.fields {
|
for field in info.fields {
|
||||||
field_sym := g.table.sym(field.typ)
|
field_sym := g.table.sym(field.typ)
|
||||||
|
|
1
vlib/v/gen/c/testdata/global_initializer_windows.must_have
vendored
Normal file
1
vlib/v/gen/c/testdata/global_initializer_windows.must_have
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Array_fixed_main__Foo_3 g_test_foo = {(main__Foo){.foo = 0,.bar = (main___VAnonStruct1){.a = 0,.b = 0,},}, (main__Foo){.foo = 0,.bar = (main___VAnonStruct1){.a = 0,.b = 0,},}, (main__Foo){.foo = 0,.bar = (main___VAnonStruct1){.a = 0,.b = 0,},}}; // global4
|
11
vlib/v/gen/c/testdata/global_initializer_windows.vv
vendored
Normal file
11
vlib/v/gen/c/testdata/global_initializer_windows.vv
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// vtest vflags: -enable-globals
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
foo int
|
||||||
|
bar struct {
|
||||||
|
a int
|
||||||
|
b f64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__global g_test_foo = [3]Foo{}
|
23
vlib/v/tests/global_init_test.v
Normal file
23
vlib/v/tests/global_init_test.v
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
@[has_globals]
|
||||||
|
module main
|
||||||
|
|
||||||
|
interface IGameObject {
|
||||||
|
mut:
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Game {
|
||||||
|
mut:
|
||||||
|
objects []IGameObject
|
||||||
|
delete_objects []IGameObject
|
||||||
|
}
|
||||||
|
|
||||||
|
__global (
|
||||||
|
game Game
|
||||||
|
)
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
println('game: ${game}')
|
||||||
|
assert game.objects.len == 0
|
||||||
|
assert game.delete_objects.len == 0
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue