🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #12879

Re: Available no. of registers

#12879
From: guy
Date: Sun, 25 Jan 1987 08:38
36 lines
2205 bytes
>A pointer points to an address in memory.  manipulating items at offsets from
>that address by using that pointer is just fine.

A pointer points to an object, not an "address in memory".  You may
be able to get away with treating pointers as if they pointed to
addresses in memory in most C implementations, but there is nothing
in any C specification that requires this to work.

Furthermore, manipulating items at offsets from that address by using
that pointer is ONLY fine if the pointer points to a member of an
array.  See K&R, 7.4 "Additive operators".

> A common valid use is to set a char pointer to the first character in a
>string and then increment the pointer to examine succesive characters.

But in this case the pointer is pointing to a member of an array,
since a string is stored in an array of characters.

>There is nothing in the language that requires the programmer to stop at
>the end of the string. . .

Depends on what you mean by "in the language".  There is nothing in
the language that guarantees that the pointer you get if you *don't*
stop at the end of the string has a meaningful, useful, or
intuitively-obvious value, or that it has the value that you'd
"expect" it to have.  It may happen to do so on existing
implementations, but don't count on it doing so on all
implementations.

>The problem occurs when you do pointer arithmetic on Y.  It is perfectly
>legitimate to write:
>
>X = *(Some_kind *) (Y+1);

Oh, no it isn't!  See 7.4 "Additive operators".  "Y" doesn't point to
an object in an array.
Technical Details
Message-ID: <12064@sun.uucp>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!ames!oliveb!sun!gorodish!guy
References: <3810002@nucsrl.UUCP> <926@mips.UUCP> <759@vaxb.calgary.UUCP> <1029@cuuxb.UUCP> <763@vaxb.calgary.UUCP> <213@ames.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!ames!oliveb!sun!gorodish!guy
From: guy@gorodish.UUCP
Newsgroups: comp.arch
Subject: Re: Available no. of registers
Message-ID: <12064@sun.uucp>
Date: Sun, 25-Jan-87 03:38:52 EST
Article-I.D.: sun.12064
Posted: Sun Jan 25 03:38:52 1987
Date-Received: Mon, 26-Jan-87 01:49:15 EST
References: <3810002@nucsrl.UUCP> <926@mips.UUCP> <759@vaxb.calgary.UUCP> <1029@cuuxb.UUCP> <763@vaxb.calgary.UUCP> <213@ames.UUCP>
Sender: news@sun.uucp
Reply-To: guy@sun.UUCP (Guy Harris)
Organization: Sun Microsystems, Mountain View
Lines: 36