array refs

cottrell at nbs-vms.ARPA cottrell at nbs-vms.ARPA
Sat Jan 12 01:56:30 AEST 1985


/*
i disagree about referencing arrays 'out of bounds'. i have often taken
a pointer, moved it down the array, when suddenly i find i have to
pervert the previous character. what do i do? something like: p[-1] = ... ;
i see nothing wrong with negative indexing, altho i dont believe in
floating point :-)
also: about the construct:
	for(p = buf; p < &buf[SIZE]; p++)
someone said it breaks at the wraparound point of memory. true, but lotsa
weird stuff happens there. i know p <= &buf[SIZE - 1] works there, but
this is a pathological case. most programs deal with address space that
look like 0 < lo < hi < wrap.
also also: another use of array refs beyond the 'bounds' is a struxure
that ends with a variable size string:

	struct weird {
		int	count;
		...
		...
		char	string[1];
	};

	w = malloc(sizeof(struct weird) + strlen(source);
	w->count = strlen(strcpy(w->string,source));

howzabout them apples?
*/



More information about the Comp.lang.c mailing list