Another silly question

Hans van Staveren sater at cs.vu.nl
Mon May 1 20:41:46 AEST 1989


In article <1513 at auspex.auspex.com> guy at auspex.auspex.com (Guy Harris) writes:
>
> >My CS instructor and I disagree about a certain moot point.  I have a text
> >book which says that
> >
> >	*(a + i)	and	a[i]
>	/* LOTS OF STUFF DELETED */
>You are correct; he is incorrect.  Perhaps he does not understand how
>pointer addition works in C?  If you add an integral value N to a pointer,
>it doesn't increment the address in that pointer by N storage units
>(bytes on byte addressible machine, etc.), it can be thought of as
>incrementing the address by N objects of the type to which that pointer
>points.  In C, pointers have types, and those types are significant.

Just to show how old I am, let me tell you that in Unix V6 on the PDP 11,
the only machine it ran on, the expressions
	a + i
and
	i + a
with a a pointer and i an integer were not equivalent.
	a + i worked as it does nowadays
while	i + a worked as this guys instructor fears.

I am even willing to admit I used this trick, but then in those days the way 
to get an unsigned was to declare it as a char* and casts were not invented
yet.

Language historians, take note!

	Hans van Staveren
	Vrije Universiteit
	Amsterdam, Holland



More information about the Comp.lang.c mailing list