■
ちょっと試してみた。Cygwin で。
isshiki1@isshiki ~/test/local
$ gcc test.c
test.c: In function `hoge':
test.c:12: warning: function returns address of local variable
isshiki1@isshiki ~/test/local
$ ls
a.exe test.c
isshiki1@isshiki ~/test/local
$ ./a
hoge 0x0022ccb4
hoge 5
ソースはこんな感じ。
#include <stdio.h> static int *hoge(void); int main(int argc, char *argv[]) { printf("hoge 0x%08x\n", hoge()); printf("hoge %d\n", *hoge()); return 0; } int *hoge(void) { int c =5; return &c; }