Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!lanl!jlg From: jlg@lanl.gov (Jim Giles) Newsgroups: comp.lang.misc Subject: Re: Answers, Chapter 1: TeX (was C's sins... and others) Message-ID: <3681@lanl.gov> Date: 24 Oct 90 00:53:57 GMT References: <26726@megaron.cs.arizona.edu> Organization: Los Alamos Natl Lab, Los Alamos, N.M. Lines: 43 From article <26726@megaron.cs.arizona.edu>, by gudeman@cs.arizona.edu (David Gudeman): > In article <3656@lanl.gov> jlg@lanl.gov (Jim Giles) writes: > > ]Of course, pointers and one dimensional arrays - in spite of their > ]similarity - are indeed different. For one thing: arrays are bounded. > > You know, Jim, it doesn't help your argument any when you keep > bringing up the same points long after they have been discredited. > Pointers are bounded just like array indexes. [...] Really? I don't know _any_ language that has pointers that places bounds on where it can point. In C, if I have an 'int' var for example, unless the int has the register attribute (in which case it's _supposedly_ not in memory anyway :-), I can have _any_ (int *) variable point to that 'int'. No matter where in memory an object is, a pointer to that type of object can point there. > [...] Yes, most > implementations of C don't check the bounds, but that is because in > the definition of the C language, run-time errors are generally > defined to produced undefined results. [...] What you are talking about here is the ANSI C (which is _very_ new) constraint on the validity of pointer _arithmetic_. This constraint merely says that comparing (or subtracting) pointers that currently point to within separately allocated objects is undefined. The same status occurs if you add (or subtract) integers to (or from) pointers so that the result leaves the bounds of a single allocated object. These constraints are present to allow certain lazy implementations on segmented archetectures to do all pointer arithmetic without refering to the segment component of the addresses. The pointer itself can still be _assigned_ to point anywhere in memory - only pointer arithmetic is effected by the constraint you mention. By the way, I opposed this ANSI specification. One of the _few_ things I think pointers are at all good for is implementing the memory manager. If pointer arithmetic across segment boundaries is not reliable, then pointers can't be reliably used to implement the memory manager (or, at least, not without considerable extra difficulty). J. Giles