anything like C++ references?

Stephen Horne intentionally at blank.co.uk
Wed Jul 16 17:38:30 EDT 2003


On 16 Jul 2003 17:51:20 -0000, Moshe Zadka <m at moshez.org> wrote:

>On Wed, 16 Jul 2003, Michael Chermside <mcherm at mcherm.com> wrote:
>
>>     stuff[i] = newComplexObject(i++, "name", "fred")
>
>I'm not entirely sure that C code is not undefined. I think it
>is, but it could be that I'm mistaken and that "=" is a "sequence point".
>It's a variant on the old
>
>a[i]=i++ 

I think you're right. The old 'when does the postincrement happen'
issue. I missed that on the first read - though admittedly not a real
debugging-mode read - but it still shows that it doesn't stand out as
obvious when you need to find the problem.

But - though I'm not sure - I think it might not be an issue in C++
rather than C. With user defined objects and stuff, the postincrement
is done immediately when the 'i++' is evaluated - a result of using a
member function to implement it. The behaviour of integers and
pointers may have been redefined to fit the same pattern. But don't
quote me on it, and certainly don't depend on it - it's an obvious
thing for many compilers to have an optimisation option for, perhaps
buried in a badly defined strict-or-optimised option.

It's going to bug me now, though.

I tend to dislike expression side effects in part because these little
mistakes are so easy. In this case...

  stuff[i] = newComplexObject(i, "name", "fred"); ++i;
  ...

...is no problem (or Adams 'len' solution, of course).





More information about the Python-list mailing list