Re: Another String reversal question
From: Dave Harris (brangdon_at_cix.co.uk)
Date: 12/23/03
- Next message: Cy Edmunds: "Re: Assignment operator"
- Previous message: Dhruv: "Re: Another String reversal question"
- In reply to: Dhruv: "Re: Another String reversal question"
- Next in thread: kanze_at_gabi-soft.fr: "Re: Another String reversal question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Dec 2003 21:09:33 -0500
dhruvbird@gmx.net (Dhruv) wrote (abridged):
> So, I guess adding 1 to the end of the array would mean that the
> higher 16-bits in the register would get incremented by 1 and
> the lower 16-bits would roll back to 0?
With some hardware, the higher 16 bits would be unchanged. Pointer
arithmetic only affected the low 16-bits; the CPU might not even
have been capable of 32-bit arithmetic directly.
Thus (char *) 0x1001ffff + 1 = (char *) 0x10010000 for these pointers,
and p > p+1.
(For some compilers, only the low 16 bits took part in pointer
comparisons, but this wasn't ratified by the standard. It meant
(char *)0x10014444 == (char *) 0x20024444, and you had to be
sure you had the right kind of NULL. Unpleasant.)
> So, isn't one past the end of the array also some memory that the
> running process might not bw owning?
It could be, but the C++ standard requires that the compiler make it
work. This may mean allocating one more byte than necessary. In
practice for alignment reasons you may need several bytes, but there
doesn't have to be a whole object there. In that respect your diagram
is misleading.
To allow one before the beginning, we would need sizeof(object) bytes,
which is more onerous because an object can be arbitrarily large.
-- Dave Harris, Nottingham, UK
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
- Next message: Cy Edmunds: "Re: Assignment operator"
- Previous message: Dhruv: "Re: Another String reversal question"
- In reply to: Dhruv: "Re: Another String reversal question"
- Next in thread: kanze_at_gabi-soft.fr: "Re: Another String reversal question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|