Any one has any idea why this code if causing glibc errors?
It seems that for some reason casting the buffer to something and then using it,
would mess up with the delete comming up later. If I change that from dynamic
allocation to simple static allocation (just char a[sizeof(s)]) and remove the delete
at the end, everything is fine.
Code:
class A {
public:
A(){}
~A() { std::cout << "I'm dying" << std::endl; }
};
struct s {
A ty;
int a;
float b;
bool c;
};
int main() {
char *a = new char(sizeof(s));
//char a[sizeof(s)];
s *obj = (s*)a;
obj->ty = A();
obj->a = 5;
obj->b = 6;
obj->c = true;
for (int i=0;i<sizeof(s);i++) {
std::cout << "a[" << i << "]=" << *a++ << std::endl;
}
delete a;
return 0;
}