invalid init of static var
This commit is contained in:
parent
d548d02e2c
commit
5f696277f7
4 changed files with 26 additions and 14 deletions
|
@ -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
13
test/lib.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
#include <stdio.h>
|
||||
|
||||
void init();
|
||||
|
||||
static struct Init {
|
||||
Init()
|
||||
{
|
||||
puts("Init");
|
||||
init();
|
||||
}
|
||||
} s_init;
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int ret123();
|
||||
#include "lib.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("ret=%d\n", ret123());
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue