Re: ANSI C clarifications, with citations (was Re: [patch-2.4

Michael Meissner (meissner@munchkin.spectacle-pond.org)
Wed, 28 Jun 2000 23:45:35 -0400


On Wed, Jun 28, 2000 at 03:28:17AM -0400, Albert D. Cahalan wrote:
>
> Larry McVoy writes:
> > Sandy said:
> >> Rusty said:
>
> >> Cast a char * to int * on any architecture with strong alignmenmt
> >> restrictions and watch your code commit messy suicide.
>
> Oh no, the cast works perfectly well. The derereference is another
> matter of course, and you'd better make sure you satisfy alignment
> needs. Cast to long and mask off bits or cast to smaller types.

Wrong. There have been machines in the past with just those restrictions.
Granted the likely hood of GCC being ported to them is slim, but they did
exist, and the C rules do acknowledge them. The one I'm most familar with is
the Data General MV/Eclipse machine that I wrote a C compiler for. The
original 16-bit machine of the series had no byte pointers, and the word
pointer format had an indirection bit as the top bit. When they finally added
byte pointers, the byte pointer was the word pointer shifted left one bit
position (losing the indirection bit), and the bottom bit was then a byte
selector. Thus sloppy code that passed pointers around (this was before the
ANSI C committee adopted prototypes from C++) tended to get burned as
invariablely you used something in byte pointer format in a word pointer
context or vica versa.

Other machines included PR1ME computers which used a 32-bit word pointer, and a
48-bit byte pointer.

-- 
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/