Checking if a string is null
Derek Parnell
derek at psyc.ward
Wed Jul 25 23:34:56 PDT 2007
On Thu, 26 Jul 2007 07:50:07 +0200, Frits van Bommel wrote:
> Derek Parnell wrote:
>> On Wed, 25 Jul 2007 14:29:47 +0100, Regan Heath wrote:
>>
>>> Aside: If the location and length are identical you can short-circuit
>>> the compare, returning true and ignoring the content, this could save a
>>> bit of time on comparisons of large arrays.
>>
>> I don't think this is such a good idea. How does one address the array of
>> four bytes at RAM location 4?
>
> I'm pretty sure the only way to obtain such an array would be to have
> already invoked Undefined Behavior (assuming 4 is an invalid memory
> location on the platform the program's running on) and as such it
> doesn't really matter whether or not two array references to it compare
> equal or not...
There is no basis for assuming that any RAM location is not addressable. I
know that some operating systems prevent unprivileged programs from
accessing certain locations, and that some RAM is hardware-mapped to I/O
ports, but in theory, D as a system language should be able to address any
RAM location.
For example, if D had been implemented for the Amiga system, access to RAM
address 4 is vital. As that location contained the 32-bit address of the
list that contains all addresses of the loaded shared libraries. And every
program needed to access that location.
--
Derek Parnell
Melbourne, Australia
"Down with mediocrity!"
More information about the Digitalmars-d-learn
mailing list