>>3
return type of *ret is value of pointer at ret. It crashes because it tries to copy the value of entire struct to the stack. instead of the pointer
you should try
return ret;
Name:
Anonymous2013-08-27 14:28
>>5
but then why does
struct something floattosomething(float f){
struct something ret;
ret.type = 3;
ret.f = f;
return ret;
}
work?
>>12
Not >>11-san, but have you considered reading a simple C reference? You're missing many basic concepts here, I don't think you're ``managing without it'' as you said.
Name:
Anonymous2013-08-27 15:06
>>13
you guys are saying that it doesn't return a copy? or that copies don't crash it?
if they don't crash it then what crashed it?
>>17
Post a complete program that crashes.
There's nothing in >>1's snippet that would cause a crash (unless you call this function millions of times and run out of memory due to the memory leak)
Yes, that is very bad. Upon returning the intended value, you have left the memory allocated for ret to sit there until the program's termination. Don't use pointers unless they're necessary, else you will be leaking memory.