Re: C vs. C++
- From: James Kuyper <jameskuyper@xxxxxxxxxxx>
- Date: Sun, 18 Jan 2009 17:34:21 GMT
CBFalconer wrote:
James Kuyper wrote:CBFalconer wrote:REH wrote:Yes, that is precisely what REH presumably meant to refer to;
... snip ...
There are a lot of things C++ has to improve portability. ForC can do that also, with an equal/notequal comparison guaranteed.
example, unlike C, C++ has a portable mechanism for comparing
unrelated pointers. The next version of the standard will
include portable mechanisms for doing such things as memory
fences and atomic operations.
What it can't do is compare pointers for relative position, if
both pointers are not to areas in a single object.
std::less<T*> provides a portable method for comparing unrelated
pointers for relative position, despite the issue you describe:
This is caused by the fact that there are NO restrictions on
where to get memory. Thus pointers can include a lot more
information than just the offset in some area.
For example, imagine a system where, after writing 0 to ioport 5,
memory addresses 1000 to 2000 address memory on one chip. After
writing 1 to ioport 5, those addresses reach another chip. There
is NO way to define greater or smaller addresses between the
chips. Yet pointers have to be able to access both!
A pointer must contain enough information to uniquely identify the location that it points at. On such a system, the pointer would have to contain enough information, directly or indirectly, for the system to determine which chip it refers to. That information can be used to determine an arbitrary ordering between pointers to data on the first chip and data on the second chip. The obvious choice would be to order all memory positions on the second chip higher than any memory position on the first chip.
So there can't be a portable method of ordering pointers. Maybe
C++ has some sort of provision that excludes such a mechanism. C
doesn't, to my knowledge.
C++ mandates such ordering; how it is achieved is up to the implementor. If there were no way around the problem you describe, then fully conforming implementation of the C++ standard library for such a platform would be impossible. This is a cost the C++ committee has decided to accept; I strongly suspect that they did not expect the cost to be significant.
.
- References:
- C vs. C++
- From: beggars . banquet
- Re: C vs. C++
- From: Tomás Ó hÉilidhe
- Re: C vs. C++
- From: CBFalconer
- Re: C vs. C++
- From: Tomás Ó hÉilidhe
- Re: C vs. C++
- From: Richard Bos
- Re: C vs. C++
- From: REH
- Re: C vs. C++
- From: jameskuyper
- Re: C vs. C++
- From: REH
- Re: C vs. C++
- From: nick_keighley_nospam
- Re: C vs. C++
- From: CBFalconer
- Re: C vs. C++
- From: REH
- Re: C vs. C++
- From: CBFalconer
- Re: C vs. C++
- From: REH
- Re: C vs. C++
- From: CBFalconer
- Re: C vs. C++
- From: James Kuyper
- Re: C vs. C++
- From: CBFalconer
- C vs. C++
- Prev by Date: Re: Big numbers
- Next by Date: Re: I can't get the uppercase letter to convert to the lower case level (Please don't bait Han from China)
- Previous by thread: Re: C vs. C++
- Next by thread: Re: C vs. C++
- Index(es):
Relevant Pages
|
Loading