[Solved] Explain function returns in c [closed]


Your message functions lack a return type. C deduces it to be int. However, not returning a value from a non-void function is Undefined Behaviour.

In your case, the return value from printf has probably been stored in a register, which was not overwritten by message before it itself returned. Thus, the return value propagated.

While this can seem to ba all good and dandy, don’t forget that UB is random by definition, and that you ought to avoid it at all cost (lest you want your program to mysteriously blow up when you change compiler / OS / Moon phase). Enabling (and acknowledging) compiler warnings would have saved you here.

solved Explain function returns in c [closed]