Re: C vs. C++
- From: Phil Carmody <thefatphil_demunged@xxxxxxxxxxx>
- Date: Sun, 18 Jan 2009 14:15:50 +0200
CBFalconer <cbfalconer@xxxxxxxxx> writes:
James Kuyper wrote:
CBFalconer wrote:
REH wrote:
... snip ...
There are a lot of things C++ has to improve portability. For
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.
C can do that also, with an equal/notequal comparison guaranteed.
What it can't do is compare pointers for relative position, if
both pointers are not to areas in a single object.
Yes, that is precisely what REH presumably meant to refer to;
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!
There is a way. In order to uniquely identify that memory location,
the '0' and '1' that are most recently written to the port are part
of the address. Otherwise 1234 in bank 0 and 1234 in bank 1 would
be compared equal, which they mustn't be. How this extra bit is
included in the numeric value being compared is arbitrary (and thus
intrinsically non-portable, as you say (snipped)).
Phil
--
I tried the Vista speech recognition by running the tutorial. I was
amazed, it was awesome, recognised every word I said. Then I said the
wrong word ... and it typed the right one. It was actually just
detecting a sound and printing the expected word! -- pbhj on /.
.
- Follow-Ups:
- Re: C vs. C++
- From: Nate Eldredge
- Re: C vs. C++
- 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: sscanf question
- Next by Date: Re: sscanf question
- Previous by thread: Re: C vs. C++
- Next by thread: Re: C vs. C++
- Index(es):
Relevant Pages
|