On Thu, 05 Jan 2006 14:28:51 +0100, David Murmann <[EMAIL PROTECTED]> wrote:
> Dan Sommers schrieb: >> int **_idx; >> for( _idx = lst; _idx < lst + NLST; ++_idx ) { >> int *i; >> i = *_idx; >> /* compare "the item to which i is bound" to "a constant" */ >> if( *i == *(&_i2) ) >> /* rebind i to _i4 */ >> i = &_i4; >> } >> for( _idx = lst; _idx < lst + NLST; ++_idx ) { >> int *i = *_idx; >> printf( "%d\n", *i ); >> } For reference, Stuart Gathman's looks like this: > > int _idx; /* internal iterator */ > > for (_idx = 0; _idx < NLST; ++_idx) { > > int *i = lst[_idx]; > i don't see what is so fundamentally different in this version > compared to the one from Stuart Gathman (except it works, but i think > it was a typo) ... I agree that Stuart's error was a typo. > ... do you want to stress that python uses an iterator (if so, i would > have renamed _idx to _iter, because it ain't not index anymore)? whats > the point of not starting the for loop at 0? ... I was trying to show iteration over a list of items, rather than indexed access into a list of pointers, but it is no longer as clear to me as it was at the time that I did a good job of that. ;-) Another thing I wanted to show is that no amount of changing i would have any effect on the list, and I missed it in Stuart's code (my fault). Or maybe my Python/C ratio is so high that seeing a loop variable used as an index into a list or an array just bugs me. ;-) _iter vs. _idx is a non-starter for me because of the baggage associated with those words. > ... and is there a difference between (*i == _idx) and (*i == > *(&_idx))? Again, just the emphasis that the comparison is through bindings rather than directly on the objects, to show that the bindings are completely independent of the objects. I am pretty sure that there is no semantic difference between *(&_idx) and _idx in the "normal" case, but there may be some very odd corner cases if _idx were volatile and/or delcared register. Regards, Dan -- Dan Sommers <http://www.tombstonezero.net/dan/> -- http://mail.python.org/mailman/listinfo/python-list