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

Walter Bright newshound2 at digitalmars.com
Fri Apr 12 11:19:52 UTC 2019


On 4/11/2019 11:52 PM, aliak wrote:
> But I think the same would apply to abs if we had not 
> grown up with it being in math.h. We'd be doing "n>0?n:-n" or 
> "(n+(n>>31))^(n>>31)" - or the more saner would write their own. And then when 
> someone comes and tries to add abs to a standard library functions one could 
> also say "not knowing about [a] common operator[s] is not a reason to add a 
> library functions".

abs() is different. Note that `n` appears multiple times in your examples, which 
matters if the expression `n` contains side effects. This side effect problem is 
a common one C programmers encounter when they use an abs() macro.

Avoiding the side effect without using the function can be awkward, thus 
justifying the function.


More information about the Digitalmars-d mailing list