Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!rochester!uhura.cc.rochester.edu!ur-valhalla!badri From: badri@valhalla.ee.rochester.edu (Badri Lokanathan) Newsgroups: comp.lang.c Subject: Re: Sizes, alignments, and maxima (was: Contiguous Arrays) Summary: Just for the sake of argument Message-ID: <1839@valhalla.ee.rochester.edu> Date: 24 Feb 89 18:15:08 GMT References: <2508@ssc-vax.UUCP> <340009@hplvli.HP.COM> Organization: UR Dept. of Electrical Engg, Rochester NY 14627 Lines: 46 In article <340009@hplvli.HP.COM>, boyne@hplvli.HP.COM (Art Boyne) writes: > Sorry, but read Henry's response more carefully: it is possible that the > *computation* of x-=i will cause an abort/trap/etc - without attempting > any *access*. This is especially likely if x=-i would result in x pointing > to a negative-index array location (consider a machine whose address > registers trapped on a negative segment offset and whose compiler put > the array into a separate segment, perhaps due to segment size limitations). > Henry is correct: pointer arithmetice isn't guaranteed unless you keep it > *within* an array. > On a slightly different note and out of curiosity, I tried the following experiment on a sun 3 running OS3.4: main() { unsigned i, j, k, val; i = 100; j = 200; k = 300; val = i - j + k; printf("%u\n", val); val = (i - j) + k; printf("%u\n", val); val = i - j; printf("%u\n", val); } The output was 200 200 4294967196 Thus even though the intermediate value was rubbish (-100), it still worked correctly. (I checked the assembler output for difference too.) Could anybody tell me of a machine where this will not run? Similarly with the pointer problem, while everybody has said that a problem *might* occur, is there a machine where failure will definitely occur? -- ,------------------------. "O! the beautiful bombs falling! | Badri Lokanathan | Children leap as deer to catch them. | badri@ee.rochester.edu | Mothers burst open like flowers. `------------------------' Fathers spin away into orange air." -Dick Bakken