Forbid dynamic arrays in boolean evaluation contexts
Steven Schveighoffer
schveiguy at yahoo.com
Tue Mar 26 10:57:47 PDT 2013
On Tue, 26 Mar 2013 13:34:02 -0400, Vladimir Panteleev
<vladimir at thecybershadow.net> wrote:
> On Tuesday, 26 March 2013 at 17:32:12 UTC, Jonathan M Davis wrote:
>> On Tuesday, March 26, 2013 12:24:56 Vladimir Panteleev wrote:
>>> [] (the literal) has .ptr as null. That may or may not be a bug.
>>
>> As I understand it, it's very much on purpose. It avoids a needless
>> memory
>> allocation.
>
> In the same way that "" allocates memory?
>
> [] can be an empty slice of *anything*, but it might as well be a
> 0-length constant in the data segment, similar to "".
"" needs to point to the data segment because it has to point to a
readable 0 character for C compatibility. The same is not true for [].
The code for [] is modifiable without changing the compiler, you certainly
can suggest something different. I think the function is _d_newarray,
there may be more than one version (one that is for 0-initialized data,
one that is not). Changing it will probably break code that depends on it
being null (intentionally or not).
But it definitely is NOT a bug. Any suggested change would be an
enhancement request.
-Steve
More information about the Digitalmars-d
mailing list