Let's say I have a struct declared in a temp.h as follows:
/* physical memory */
typedef struct pmem_struct {
uint32_t val;
} pmem_s, *pmem_p;
And lets say I declare this struct in my temp.c file in the method pmem_p pmem_new() like so:
pmem_p pmem_new() {
pmem_s pmems;
pmem_p pmem = &pmems;
pmem->val = 0;
//printf(stderr, "From Mem: %x\n", pmem->val);
return pmem;
}
Now here is my main.c file:
#include <stdio.h>
#include "temp.h"
#include "gen.h"
int main() {
pmem_p pmem = pmem_new(); /* create some physical memory */
fprintf(stderr, "From Mem: %x\n", pmem->val);
......
}
Why is it that this fprintf prints out From Mem: 4019cff4, unless I uncomment the fprintf line in pmem_new(), at which the both correctly print out From Mem:0