This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Large pointer differences -- is this a bug
- To: gcc-help at gcc dot gnu dot org
- Subject: Large pointer differences -- is this a bug
- From: Steve Linton <sal at dcs dot st-and dot ac dot uk>
- Date: Fri, 19 Oct 2001 15:39:19 +0100
In a C program on x86 architecture, I have a large (>2GB) array of 4-byte
objects. Suppose I have two pointers s pointing near the start of the array
and e pointing near the end. Now suppose I compute (e-s). gcc (all versions I
have tried up to 3.01) produces code that does the subtraction and then does a
signed right shift 2, producing a value near -0.5G, instead of the value I
would like, of +0.5G. Since the correct value can be expressed in a ptrdiff_t
(an int) I feel it should be, but I can't see a clear statement in ANSI. gdb,
evaluating it interactively gives me the result I expect.
So, is this a bug?
I also started wondering what behaviour should I expect if my array contained
1 byte objects? Then ptrdiff_t is not actually a big enough type to contain
the full range of possible answers (-3G to +3G on Linux).
Steve Linton