food for thought - swift 5 released - bottom types, string interpolation, and stuff.

Julian julian.fondren at gmail.com
Sat Apr 13 08:20:52 UTC 2019


On Saturday, 13 April 2019 at 07:57:32 UTC, Julian wrote:
> On Saturday, 13 April 2019 at 07:49:13 UTC, Nick Sabalausky 
> (Abscissa) wrote:
>> On 4/13/19 1:37 AM, Walter Bright wrote:
>>> On 4/12/2019 10:18 PM, H. S. Teoh wrote:
>>>> writing (x % 2) conveys intent much better
>>>> than (x & 1).
>>> 
>>> They produced different code. Try this with your favorite C 
>>> compiler:
>>> 
>>> int foo(int x)
>>> {
>>>      return x % 2;
>>> }
>>> 
>>> int bar(int x)
>>> {
>>>      return x & 1;
>>> }
>>
>> Sounds like compiler room-for-improvement.
>
> Contrast https://godbolt.org/z/aN8rRV

er, these actually have the same unoptimized and -O3 output:

   int foo(int num) {
       return 0 == num % 2;
   }

   int bar(int num) {
       return 0 == (num & 1);
   }

https://godbolt.org/z/oqP0Mn


More information about the Digitalmars-d mailing list