Should you be able to initialize a float with a char?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu May 19 20:24:33 UTC 2022


On Thu, May 19, 2022 at 10:33:14AM -0400, Steven Schveighoffer via Digitalmars-d wrote:
> On 5/19/22 12:35 AM, Walter Bright wrote:
[...]
> > The APL language relies on bools being integers so conditional
> > operations can be carried out without branching :-)
> > 
> > I.e.
> >      a = (b < c) ? 8 : 3;
> > 
> > becomes:
> > 
> >      a = 3 + (b < c) * 5;   // I know this is not APL syntax
> > 
> > That works in D, too!
> 
> I hope we are not depending on the type system to the degree where a
> bool must be an integer in order to have this kind of optimization.
[...]

IME, gcc and ldc2 are well able to convert the above ?: expression into
the latter, without uglifying the code.  Why are we promoting (or even
allowing) this kind of ugly code just because dmd's optimizer is so
lackluster you have to manually spell things out this way?


T

-- 
Without outlines, life would be pointless.


More information about the Digitalmars-d mailing list