I meant x = 1, sorry. The code came right from the article, so the 8 was there to change the return value so it skipped the x = 1, but his disassembly is different than mine. I was not sure what -O1 and -O2 did so I tryed it and it didn't seem to do anything extra, I just get "assignment from incompatible pointer type", like before.
EDIT: A little man gcc gave the answer to what -O is for , and the gdb output has changed quite a bit
The point is, the value you add to (*ret) depends on the machine code used in the function you're returning to. I think it should be 7 in the listing you posted, but as soon as you change main(), or you change compilers, or optimization settings, the machine code will change.
7 doesn't seem to work :-\. When I change the return value everything seems to just work as normal. Considering I'm changing it, wouldn't it mess everything up?
The point is:
-- Look at the disassembly. Work out where the CPU would return to after the CALL <function> instruction
-- Work out where you want the CPU to return to instead
-- Work out the difference between these two values
-- Increment the return address by this amount