🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #187

Re: Intermediate addr outside object: legal?

#187
From: Barry Margolin
Date: Wed, 08 Apr 1992 06:35
26 lines
1809 bytes
In article <2160002@aspen.IAG.HP.COM> shankar@aspen.IAG.HP.COM (Shankar Unni) writes:
>This, of course, does not address the question of what is "the right
>thing to do" when the compiler sees this expression (the user-
>friendliness question).  Is it reasonable for the program to get a
>SIGSEGV on this?  I.e. is this some sort of commonly used (albeit
>questionable) idiom in some context that I'm not aware of?

It depends on what you mean by "user-friendliness".  Which is more
friendly: warning the programmer that their program may not port easily, or
doing what the programmer probably expects?

This kind of code generally arises when you want to emulate arrays whose
indices start at something other than 0.  For instance, if you want the
first element to be index 1, you would decrement the array pointer.

This restriction exists because some C implementations are known to fault
when computing addresses outside of arrays.  When performing pointer
arithmetic they use address registers, and on some architectures address
registers are checked for validity when they are loaded.  Whether this is a
Good Thing is debatable (the hardware designers presumably thought it was,
but what do they know? :-), but we're stuck with such hardware.
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

barmar@think.com          {uunet,harvard}!think!barmar
Technical Details
Message-ID: <ku551sINNk3l@early-bird.think.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!barmar
References: <2160001@aspen.IAG.HP.COM> <2160002@aspen.IAG.HP.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!barmar
From: barmar@think.com (Barry Margolin)
Newsgroups: comp.std.c
Subject: Re: Intermediate addr outside object: legal?
Date: 8 Apr 1992 06:35:40 GMT
Organization: Thinking Machines Corporation, Cambridge MA, USA
Lines: 26
Message-ID: <ku551sINNk3l@early-bird.think.com>
References: <2160001@aspen.IAG.HP.COM> <2160002@aspen.IAG.HP.COM>
NNTP-Posting-Host: godot-1.think.com