Sizes, alignments, and maxima (was: Contiguous Arrays)
Badri Lokanathan
badri at valhalla.ee.rochester.edu
Sat Feb 25 04:15:08 AEST 1989
In article <340009 at hplvli.HP.COM>, boyne at 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 at ee.rochester.edu | Mothers burst open like flowers.
`------------------------' Fathers spin away into orange air." -Dick Bakken
More information about the Comp.lang.c
mailing list