is this array access portable?

der Mouse mouse at thunder.mcrcim.mcgill.edu
Mon Jun 24 04:53:51 AEST 1991


Suppose `sometype' is a type, and `something' is a valid thing to
assign to an object of that type, and I write

	sometype foo[40][50];
	sometype *fp;
	int i;

	fp = &foo[0][0];
	for (i=2000;i>0;i--) *fp++ = something;

Is this portable?  (The significant question is whether the wraparound
from the end of one row to the beginning of the next is guaranteed to
work correctly.)  I *think* enough promises are made that this will
work, but I'd like to get a few second opinions before writing this
into some code.  The thing that makes me think it has to work is a
sentence in the New Testament A7.4.8 (page 204): ``[...]: the size of
an array of n elements is n times the size of one element.'', which,
applied recursively, appears to imply that the elements of an
N-dimensional array must be packed together as if in a one-dimensional
array of the appropriate size.  (I'm also not *quite* certain that even
if this is true, a pointer can sleaze past the boundary safely....)

					der Mouse

			old: mcgill-vision!mouse
			new: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list