invalid init of static var

This commit is contained in:
MITSUNARI Shigeo 2012-12-02 21:28:30 +09:00
parent d548d02e2c
commit 5f696277f7
4 changed files with 26 additions and 14 deletions

View file

@ -49,12 +49,8 @@ test_avx: normalize_prefix
clean:
rm -rf *.o $(TARGET)
lib_test.a: lib_test.cpp
$(CXX) -c $(CFLAGS) lib_test.cpp
ar r lib_test.a lib_test.o
lib_run: lib_test.a lib_run.cpp
$(CXX) $(CFLAGS) lib_run.cpp lib_test.a -o lib_run
lib_run: lib_test.cpp lib_run.cpp
$(CXX) $(CFLAGS) lib_run.cpp lib_test.cpp -o lib_run
make_nm: make_nm.cpp $(XBYAK_INC)

13
test/lib.h Normal file
View file

@ -0,0 +1,13 @@
#pragma once
#include <stdio.h>
void init();
static struct Init {
Init()
{
puts("Init");
init();
}
} s_init;

View file

@ -1,9 +1,6 @@
#include <stdio.h>
int ret123();
#include "lib.h"
int main()
{
printf("ret=%d\n", ret123());
}

View file

@ -1,17 +1,23 @@
#include "lib.h"
#include <xbyak/xbyak.h>
struct Code : public Xbyak::CodeGenerator {
Code()
{
mov(eax, 5);
printf("Code:%s\n", eax.toString());
ret();
}
};
int ret123()
void init()
try
{
static bool init = true;
printf("in lib_test %d\n", init);
if (!init) return;
init = false;
static Code code;
int (*f)() = (int (*)())code.getCode();
return f();
} catch (const Xbyak::Error& e) {
printf("err=%s\n", Xbyak::ConvertErrorToString(e));
}