40060Re: Mainly noise
- Jul 5, 2005Bram Moolenaar did utter on 05/07/2005 10:29:
> James Widman wrote:I would hope any good-old C programmer would spot the possibility of
>>Anyway: (i = ++i) seems, at first glance, like a safe (albeit
>>questionable) expression. One might think (as I did) that,
>>regardless of which side of '=' is evaluated first, the result is
>>the same. But ISO C99, section 6.5,p2 says:
>>"Between the previous and next sequence point an object shall have
>>its stored value modified at most once by the evaluation of an
>>So according to C99, (p = vim_strchr(++p, '/')) results in undefined
>>behavior because p is modified twice.
>>ISO C++ has basically the same verbiage. I don't have our copies of
>>ISO C90 or the first-edition K&R C book nearby, so I don't yet know
>>the situation there.
> The problem here is the standard. C99 is probably the worst C standard
> that was ever made. It was clearly formed by politicians, not by
> practical programmers. OK, well, that's just my opinion (a ran into a
> couple of annoying problems).
> That "undefined behavior" is stupid. Of course every good-old C
> programmer can predict what should and will happen. Only very bad C
> compilers would not be able to deal with it. The standard should be
> adjusted to meet what programmers do and expect, not the other way
undefined behaviour and rewrite the expression to remove the problem.
On some processors a good optimising compiler (producing correct fast
code for well defined C) would fail with this invalid code. Side
effects and sequence points are standard fare for any C job interview.
Is there a lawyer in the house? <BLAM!!> Is there another?
- << Previous post in topic Next post in topic >>