Is there something I must know?
This delay routine does *nothing* as far as the rest of the program is
concerned, so it would be a perfectly legitimate compilation of it to
translate it in to:
void delay(void)
{
}
counter is not externally visible, so its value on completion is irrelevant.
If you want to do a delay routine, you should do it in assembler code,
since otherwise there is no reasonable guarantee of what result you'll get
on any given compiler. Even if you label the counter variable "volatile"
and the compiler actually has to count through them all in order, the
amount of time it will take is pretty much random depending on the
compiler version, optimizing flags, etc.
Better yet would be to use a timer of course, although that is not always
possible.
I have to admit, it is an odd optimization!
Peter.