simple test for init

This commit is contained in:
MITSUNARI Shigeo 2012-12-03 09:09:18 +09:00
parent 5f696277f7
commit 3f66cdac5d
4 changed files with 32 additions and 14 deletions

View file

@ -47,7 +47,7 @@ test_avx: normalize_prefix
./test_avx.sh 64
./test_avx.sh Y64
clean:
rm -rf *.o $(TARGET)
rm -rf *.o $(TARGET) lib_run
lib_run: lib_test.cpp lib_run.cpp
$(CXX) $(CFLAGS) lib_run.cpp lib_test.cpp -o lib_run

View file

@ -1,6 +1,33 @@
#pragma once
#include <stdio.h>
struct A {
int a;
A()
: a(5)
{
puts("A cstr");
}
~A()
{
puts("A dstr");
}
void put() const
{
printf("a=%d\n", a);
}
};
template<int dummy = 0>
struct XT {
static A a;
};
template<int dummy>
A XT<dummy>::a;
typedef XT<0> X;
void init();
static struct Init {

View file

@ -2,5 +2,7 @@
int main()
{
puts("main");
X::a.put();
}

View file

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