Broken compilers (Was Portability of passing/operating on structures)

Tim Olson tim at crackle.amd.com
Tue Oct 25 10:30:40 AEST 1988


In article <7356 at ihlpl.ATT.COM> knudsen at ihlpl.ATT.COM (Knudsen) writes:
| Big-Endian (walkie-talkie company) micros also pose an interesting
| problem in casting an (int *) to a (char *); to do this right
| the compiler should add 1, but does not.  No problem once you
| realize it -- after all, C is structured assembler, eh?
| 
| Actually I like the semantics that casting any pointer to (char *)
| means "keep the numerical address value the same."

Huh?  Why should a Big-Endian machine add 1 when casting from an (int *)
to a (char *)?  The address that points to an integer also (by
definition) points to the first character at that address (32-bit ints
assumed, here):

		Little Endian			   Big Endian
        byte #   3  2  1  0            	  byte #   0  1  2  3
                +--+--+--+--+                     +--+--+--+--+ 
                |'d|'c|'b|'a|   <- 'abcd'         |'a|'b|'c|'d|   <- 'abcd'
                +--+--+--+--+                     +--+--+--+--+ 
                +--+--+--+--+                     +--+--+--+--+ 
                |00|00|00|03|   <- 3              |00|00|00|03|   <- 3        
                +--+--+--+--+                     +--+--+--+--+
                            ^                     ^
                pointer points here               pointer points here


Both Big Endian and Little Endian are internally consistent.

	-- Tim Olson
	Advanced Micro Devices
	(tim at crackle.amd.com)



More information about the Comp.lang.c mailing list