Checking return value of a function without return statement

Basically what gets returned is dumb luck. You get what happens to be in the CPU register when it comes back. If, for example, the returned value would be in AX, and the char* happens to be in AX, you lucked out. I believe this is an undefined behavior; i.e. the C language specifications don’t tell what you should so, so it is left to the compiler. I’m surprised a modern compiler wouldn’t at least throw a warning at you.

Leave a Comment