4 ms·
Is is the opposite. The original C compiler produced instructions very closely to the higher level language. As such, it produces code based on what you tell i
by mianos 5y ago
Is is the opposite. The original C compiler produced instructions very closely to the higher level language.
As such, it produces code based on what you tell it, no more, no less. If you don't tell it what value to return from a subroutine, it does not generate the code to. It is quite common to have a function that does not return a value.
The case shown here is not a case of the compiler doing 'what it likes', but the compiler not emitting any code for it. The fact that the return value from the function called last is still in the register used to return values when the function returns is simply a result of no code that touches that register in between.
As someone else pointed out, if you look at the code generated for a PDP-11 all the quirky things like, pointers with pre or post increment operators make much more sense as they emit instructions that do just that.
- GoblinSlayer 5y agoIs it undefined behavior?
- mianos 5y agoIf you wrote the same thing in assembly language and, by convention, you return the value from a subroutine in the AX register. This function is not returning anything useful so you don't 'MOV AX,blah', yet your caller expected something in it, is it undefined? Does the AX register exist in the caller? Yes. Does it have a value? Yes. Is its 'value' undefined. Yes. Is there any undefined 'behaviour' of anything you told it to do? Not to me. Subtle maybe.
- GoblinSlayer 5y agoI mean what the C standard says about it.