動的に領域を確保する関数
メッセ送りつけられたので、晒しage。
#include <stdio.h> #include <stdlib.h> #include <string.h> struct _hoge { char a[17]; int b; char c[19]; }; void alloc(struct _hoge *ptr) { ptr = (struct _hoge *)malloc(sizeof(struct _hoge)); printf("alloc: %p\n", ptr); } int main(void) { struct _hoge *p; alloc(p); printf("main: %p\n", p); memset(p->a, 'a', 17); p->b = 1; memset(p->c, 'c', 19); return printf("FINISH\n"); }
ありえん。チミは今まで一体何をベンキョーしてきたのかね(;´Д`)
でもって
allocとmainでポインタの値が違うしwFINISH出ないしそのかわりになんとかfaultとか出るしwコンパイラのバグなんじゃねwwWWwww
だそうで。segv 出て当たり前。だってウンココードだもの。おまいさんがコンパイラのバグを疑うなんて死んでも早過ぎる。それと草生やし杉。
非常にウザいので、正解だけ示して俄然放置。
#include <stdio.h> #include <stdlib.h> #include <string.h> struct _hoge { char a[17]; int b; char c[19]; }; void alloc(struct _hoge **ptr) { *ptr = (struct _hoge *)malloc(sizeof(struct _hoge)); printf("alloc: %p\n", *ptr); } int main(void) { struct _hoge *p; alloc(&p); printf("main: %p\n", p); memset(p->a, 'a', 17); p->b = -1; memset(p->c, 'c', 19); printf("FINISH\n"); return 0; }
そしたら、
原因はreturn printf()だなwwwwwwWWWww
うん。死ねばいいよ。