alloc_apple
fails to return new_apple;
at the end. This may work by coincidence if new_apple
happens to be left lying around in the register the return value is expected in when the function returns (on i386 this is usually EAX
), but allowing control to reach the end of a non-void
returning function produces undefined behavior (which may include anything from accidentally working as expected to causing demons to fly out of your nose).
I am fairly certain that if you compile with gcc -Wall
(enable all warnings) it would point out the issue; return-type
is the specific warning.
The function wouldn't even work for compilers that use the ancient convention of returning the value of the last expression evaluated if no return
is present, since the last expression evaluates to the value of color
.