Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!amdcad!crackle!tim From: tim@crackle.amd.com (Tim Olson) Newsgroups: comp.lang.c Subject: Re: Broken compilers (Was Portability of passing/operating on structures) Message-ID: <23362@amdcad.AMD.COM> Date: 25 Oct 88 00:30:40 GMT References: <8810111934.AA21941@ucbarpa.Berkeley.EDU> <8308@alice.UUCP> <73946@sun.uucp> <7356@ihlpl.ATT.COM> Sender: news@amdcad.AMD.COM Reply-To: tim@crackle.amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc. Sunnyvale CA Lines: 31 Summary: Expires: Sender: Followup-To: In article <7356@ihlpl.ATT.COM> knudsen@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@crackle.amd.com)