Re:3 years of computing... the palindrome quest
by PassTheAmmo on Monday July 19, 2010 @07:21AM
(#1528265)
I had to try it just because I wanted to know. With -Wall GCC says:
pquest.c:279: warning: operation on 'fp' may be undefined
Not sure what 'may' means though
EDIT:
So to clarify, my suspicion is that the expression could mean either:
1)
*fp = *fp >> 4;
*fp++;
or2)
*fp = *(fp+1) >> 4;
*fp++;
Re:3 years of computing... the palindrome quest
by BrandonM on Monday July 19, 2010 @10:35AM
(#1528781)
It is not the addressed value which is being incremented, but the pointer itself. There is no ambiguity.
Re:3 years of computing... the palindrome quest
by PassTheAmmo on Monday July 19, 2010 @11:08AM
(#1528905)
I never claimed that the addressed value would be incremented, and that is not what is being discussed here, even though that too would have been a problem.
The thing is, at some point the compiler must calculate the address where to store the value. The question is then if there is a sequence point between calculating the data to store and the address which to store to. Otherwise there is ambiguity and the result is undefined.
According to http://en.wikipedia.org/wiki/Sequence_point there is no sequence point because of assignment (only initialization which this is not)
Btw was it you that downvoted my comment?
It's certainly confusing code, but I'm fairly sure the outcome is well-defined. That doesn't mean it's good code: I'd never write it like that. I find this far easier to understand, and that's how I'd write it in practice:
The postfix while condition isn't one of my favourites either, but not quite as confusing.