Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!amdcad!crackle!tim From: tim@crackle.amd.com (Tim Olson) Newsgroups: comp.arch Subject: Re: Endian wars Message-ID: <24384@amdcad.AMD.COM> Date: 8 Feb 89 19:44:14 GMT References: <6133@columbia.edu> <3300050@m.cs.uiuc.edu> <8480@aw.sei.cmu.edu> Sender: news@amdcad.AMD.COM Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc. Sunnyvale CA Lines: 26 Summary: Expires: Sender: Followup-To: In article <8480@aw.sei.cmu.edu> firth@bd.sei.cmu.edu (Robert Firth) writes: | >while (*p++ = *q++); | | This is a neat and beautiful idiom in PDP-11 Assembler. There is, | however, one problem with the equivalent C code: it is incorrect. | After termination of the loop, the variables p and q, though declared | of type 'pointer-to-char', will hold values that do not point to | declared or allocated objects of type 'char'. Should you ever have | the misfortune to port this code to a machine with hardware segmentation, | and automatic segment bounds checking as part of the address arithmetic, | (or be a consultant involved in such a port), you will face this | problem. | | Could someone inform me whether the current C standard has fixed this? | The simplest answer I guess is to rule that the address of array[upb+1] | must always be legal; in practice this means the implementation has to | leave dead space at the end of each memory segment. That is exactly what is done in the current proposed ANSI C standard; the address is legal to compute, although dereferencing the address is undefined. Only a single byte of "dead space" is required for this. -- Tim Olson Advanced Micro Devices (tim@crackle.amd.com)