🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #12888

Re: Available no. of registers

#12888
From: Gregory Smith
Date: Tue, 27 Jan 1987 21:07
50 lines
2495 bytes
In article <213@ames.UUCP> fouts@orville.UUCP (Marty Fouts) writes:
>A pointer points to an address in memory.  manipulating items at offsets from
>that address by using that pointer is just fine.  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.  There is nothing in the language
>that requires the programmer to stop at the end of the string. . .

Given:
struct foo{
	char blat[3];
	float klotz;
} bar;

.. there is no 'i' such that the address of 'bar.blat[i]' is the same as
the address of 'bar.klotz' on any machine. Actually there has been a long
discussion on comp.lang.c recently about how to generate such an 'i'
portably, and it isn't pretty.

>The magic in C is that any kind of pointer can be assigned the address of
>any kind of data, provided that the data has an address (lvalue in K&R)
>via the classic cast:

This is exactly the kind of 'magic' that has given C an undeserved bad
name.
>
>Some_kind X;
>Other_kind *Y ;
>
>Y = (Other_kind *) &X;
>
>
>This is used heavily in C.
 Only when dealing with chunks of 'raw' memory, i.e. with malloc().
>  The semantics of many Un*x kernels and more than
>a few applications programs would break without it.  The problem occurs when
>you do pointer arithmetic on Y.  It is perfectly legitimate to write:
>
>X = *(Some_kind *) (Y+1);
>
>and get at whatever is one Sizeof(Other_kind) beyon the original X in
>memory.

What that is, if anything, depends on many things. I'd rather use the
facilities built officially into the language to address things in a
well-defined way.

-- 
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg
Have vAX, will hack...
Technical Details
Message-ID: <4016@utcsri.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utcsri!greg
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
Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utcsri!greg
From: greg@utcsri.UUCP (Gregory Smith)
Newsgroups: comp.arch
Subject: Re: Available no. of registers
Message-ID: <4016@utcsri.UUCP>
Date: Tue, 27-Jan-87 16:07:08 EST
Article-I.D.: utcsri.4016
Posted: Tue Jan 27 16:07:08 1987
Date-Received: Tue, 27-Jan-87 21:55:07 EST
References: <3810002@nucsrl.UUCP> <926@mips.UUCP> <759@vaxb.calgary.UUCP> <1029@cuuxb.UUCP> <763@vaxb.calgary.UUCP> <213@ames.UUCP>
Reply-To: greg@utcsri.UUCP (Gregory Smith)
Organization: CSRI, University of Toronto
Lines: 50