This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Large pointer differences -- is this a bug



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]