Here is the warning I get:Code:#include<stdio.h> struct face { int c; }; typedef struct face face; face * get_face() { face f = {4}; return &f; } int main() { face * f = get_face(); printf("face c: %d\n", f->c); return 0; }
warning: address of local variable ‘f’ returned
Since I'm creating face on the stack, shouldn't it go away once the function exits? However, it only throws a warning and still runs perfectly fine (prints 4).
Why does this run correctly? Is it guaranteed to run correctly?



2Likes
LinkBack URL
About LinkBacks




