Hello all, I wrote a quick program which executes every statement before giving a seg fault error.
struct foo
{
int cat;
int * dog;
};
void bar (void * arg)
{
printf("o hello bar\n");
struct foo * food = (struct foo *) arg;
printf("cat meows %i\n", food->cat);
printf("dog barks %i\n", *(food->dog));
}
void main()
{
int cat = 4;
int * dog;
dog = &cat;
printf("cat meows %i\n", cat);
printf("dog barks %i\n", *dog);
struct foo * food;
food->cat = cat;
food->dog = dog;
printf("cat meows %i\n", food->cat);
printf("dog barks %i\n", *(food->dog));
printf("time for foo!\n");
bar(food);
printf("begone!\n");
cat = 5;
printf("cat meows %i\n", cat);
printf("dog barks %i\n", *dog);
// return 0;
}
which gives a result of
cat meows 4
dog barks 4
cat meows 4
dog barks 4
time for foo!
o hello bar
cat meows 4
dog barks 4
begone!
cat meows 5
dog barks 5
Segmentation fault (core dumped)
I'm not really sure why it seg faults at the end? Any comments/insights are deeply appreciated.