Static Analysis Tooling / Effective D

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 24 06:53:00 PDT 2014


On 04/24/14 14:49, Marco Leise via Digitalmars-d wrote:
> Am Thu, 24 Apr 2014 13:11:18 +0200
> schrieb Artur Skawina via Digitalmars-d
> <digitalmars-d at puremagic.com>:
> 
>> `size_t x = 1 << shiftAmount` is definitely not something that
>> should be recommended, see above. Just use the correct type on
>> the lhs of shift operators.
> 
> auto x = cast(size_t) 1 << shiftAmount;  // really ?! :(

Yes. D has not improved the situation in this area; it's no
different from C.

A new enough compiler could make it look slightly better:

    auto x = size_t(1) << shiftAmount;


Of course the more fundamental problem is that 'size_t' is just
an alias and not a distinct type in D.

artur


More information about the Digitalmars-d mailing list