Forbid dynamic arrays in boolean evaluation contexts
deadalnix
deadalnix at gmail.com
Tue Mar 26 20:21:35 PDT 2013
On Tuesday, 26 March 2013 at 23:57:32 UTC, bearophile wrote:
> Timon Gehr:
>
>> IOW, what is the point of "null" if you can just use [].
>
> I usually prefer to use [], because null is a literal for
> pointers and class references, while [] is a literal specific
> for arrays (and strings), so its meaning is more clear (in D
> I'd even like a [:] literal that represents an empty
> associative array).
>
> On the other hand if you compile a program that uses null
> instead of [] you see some differences. In the current dmd
> compiler returning null is more efficient. I have seen code
> where this difference in performance matters:
>
>
> int[] foo() {
> return [];
> }
> int[] bar() {
> return null;
> }
> void main() {}
>
>
>
> _D4temp3fooFZAi:
> L0: push EAX
> mov EAX,offset FLAT:_D11TypeInfo_Ai6__initZ
> push 0
> push EAX
> call near ptr __d_arrayliteralTX
> mov EDX,EAX
> add ESP,8
> pop ECX
> xor EAX,EAX
> ret
>
> _D4temp3barFZAi:
> xor EAX,EAX
> xor EDX,EDX
> ret
>
> Bye,
> bearophile
That is a compiler bug isn't it ?
More information about the Digitalmars-d
mailing list