🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #998

Re: Relationship between C and C++

#998
From: Dr A. N. Walker
Date: Mon, 26 Mar 1990 18:14
58 lines
2867 bytes
In article <14286@lambda.UUCP> jlg@lambda.UUCP (Jim Giles) writes:

>From article <1990Mar22.181947.27026@maths.nott.ac.uk>, by
>anw@maths.nott.ac.uk (Dr A. N. Walker):
>> [...]                          Yes, aliassing is a problem for optimising
>> compilers, and if used casually is a problem for program-proving;  but
>> exactly the same problems arise with arrays, [...]

>NO!  The same problem does NOT arise with arrays.

	OK, I'm not deaf.

>						    Two different arrays
>are two different objects.  Period.

	So, there are some occasions where a compiler can be sure that
a[i] and b[j] are different objects;  and it's relatively harder to be
sure that pa, pb point into different objects.  On the other hand, if
a and b are parameters, they *may* (in C and many other languages) be
the same array, and EXACT... (sorry) exactly the same problems arise.

>				      Two different pointers might both
>point to the SAME object.  This behaviour of pointers is not only legal
>in all languages, it is encouraged.

	What form does this encouragement take?  I often initialise one
pointer by reference to another, but that's just common sense.  It's
hard to imagine that adding a restriction to prevent this would make
anyone's life easier.

	(In similar vein, I once used a language [Babel] in which it was
illegal to assign to a variable twice without the variable being used in
the meantime.  The implementor wisely took a holiday immediately after
adding this feature to his compiler.)

>[...]				 But, the implementor can optimize array
>usage with a clear conscience - after all, only illegal programs get
>broken. [...]

	The question was about C pointer arithmetic.  In C, legal programs
also get broken if potentially aliassed arrays are optimised as though
they are not aliassed.

>[I know - still beating the same dead horse.  This issue NEVER seems to
>go away.]

	Well, it helps if we are all looking at the same horse.  The point
at issue is not whether C or Fortran or Pascal or ... has better arrays, or
better rules about side-effects, but whether pointer arithmetic should be
considered harmful.  Unless someone has a more convincing example than we
have seen so far, the answer is no.  You should use it when it is right to
do so, and not otherwise. [:-)]

>J. Giles

-- 
Andy Walker, Maths Dept., Nott'm Univ., UK.
anw@maths.nott.ac.uk
Technical Details
Message-ID: <1990Mar26.181444.11727@maths.nott.ac.uk>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!kl-cs!nott-cs!piaggio!anw
References: <1990Mar22.181947.27026@maths.nott.ac.uk> <14286@lambda.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!kl-cs!nott-cs!piaggio!anw
From: anw@maths.nott.ac.uk (Dr A. N. Walker)
Newsgroups: comp.lang.misc
Subject: Re: Relationship between C and C++
Message-ID: <1990Mar26.181444.11727@maths.nott.ac.uk>
Date: 26 Mar 90 18:14:44 GMT
References: <1990Mar22.181947.27026@maths.nott.ac.uk> <14286@lambda.UUCP>
Reply-To: anw@maths.nott.ac.uk (Dr A. N. Walker)
Organization: Maths Dept., Nott'm Univ., UK.
Lines: 58