I'm either missing something small or theres a BIG problem somewhere. The following code compiles sucessfully with g++ 4.1.0 under SuSE 10.1 i586 (Linux 2.6.16.13-4-default i686) but it gives a Segmentation Fault when I run it.
#include <stdio.h>
#include <list>
typedef struct {
std::list<int> b;
} data;
int main(int argc, char **argv) {
data *tmp = (data*)malloc(sizeof(data));
printf("Hello1\n");
tmp->b.push_back(3);
printf("Hello2\n");
return 0;
}
Output:
Hello1
Segmentation fault
In fact, any operation on the list (and only the list, everything else works fine, even other members inside the same struct) results in some kind of segmentation fault as if the list needs initialization.
Any help will be appreciated (a lot).