Re: [dev] [st PATCH 1/3] xloadcols: remove cp variable

From: Roberto E. Vargas Caballero <>
Date: Mon, 4 May 2015 12:25:31 +0200

> > It is no casuality they added this rule to the standard. They added
> > it because is the idiomatic way of running over an array in C. Of
> > course CS teachers that liked pascal don't teach it anymore when
> > they were forced to move to C, but it is the best way for experienced

> The code in question was not comparing Q against P+1, it was
> comparing Q against P, where `P = &array[len+1]`, which is a subtly
> different case. The first increments a pointer by the size of one
> element, while the second accesses the array element just after
> the end of the array and obtains a reference to that point in
> memory. The first is dealing with a number in memory, the second
> is accessing memory to get a pointer to it. Nothing in the 3.3.8
> section affects this.

Ok, I am not going to follow this discussion. If you want to
understand this exception of pointer comparision you can find it
in K&R book. Basically it says that a comparision with one position
after the end of the array is valid.

> for (cp = colors; cp < &colors[LEN(colors)] + 1; cp++)

LEN returns a value from 1 to N, and valid indexes for the
array are from 0 to N-1. So cp < color[N] is the case described
in the standard.

Received on Mon May 04 2015 - 12:25:31 CEST

This archive was generated by hypermail 2.3.0 : Mon May 04 2015 - 12:36:07 CEST