Re: ushort + ushort = int?

2018-08-21 Thread Jim Balter via Digitalmars-d-learn
On Monday, 20 August 2018 at 08:34:56 UTC, Andrey wrote: Hello, Here is a code that you can execute using online compiler https://run.dlang.io/: import std.stdio; void main() { ushort first = 5; ushort second = 1000; ushort result = first + second; writeln(result); } I hae thi

Re: ushort + ushort = int?

2018-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 20, 2018 4:29:56 AM MDT Andrey via Digitalmars-d-learn wrote: > On Monday, 20 August 2018 at 09:56:13 UTC, Jonathan M Davis wrote: > > It's a combination of keeping the C semantics (in general, C > > code is valid D code with the same semantics, or it won't > > compile) and the f

Re: ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 09:56:13 UTC, Jonathan M Davis wrote: It's a combination of keeping the C semantics (in general, C code is valid D code with the same semantics, or it won't compile) and the fact that D requires casts for narrowing conversions. When you add two shorts in C/C++, it c

Re: ushort + ushort = int?

2018-08-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 20, 2018 3:19:04 AM MDT Andrey via Digitalmars-d-learn wrote: > On Monday, 20 August 2018 at 08:49:00 UTC, rikki cattermole wrote: > > Yes. On x86 int's will be faster just an FYI so it does make > > sense to use them for computation. > > Inconveniently always use casts. Why in D

Re: ushort + ushort = int?

2018-08-20 Thread rikki cattermole via Digitalmars-d-learn
On 20/08/2018 9:19 PM, Andrey wrote: On Monday, 20 August 2018 at 08:49:00 UTC, rikki cattermole wrote: Yes. On x86 int's will be faster just an FYI so it does make sense to use them for computation. Inconveniently always use casts. Why in D one decided to do in such way? C.

Re: ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 08:49:00 UTC, rikki cattermole wrote: Yes. On x86 int's will be faster just an FYI so it does make sense to use them for computation. Inconveniently always use casts. Why in D one decided to do in such way?

Re: ushort + ushort = int?

2018-08-20 Thread rikki cattermole via Digitalmars-d-learn
On 20/08/2018 8:48 PM, Andrey wrote: On Monday, 20 August 2018 at 08:42:20 UTC, rikki cattermole wrote: It's called integer promotion and it originates from C. And yes C++ does have such support in some variant (I really don't feel like comparing the two). And I should do? Always use "cast" o

Re: ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
On Monday, 20 August 2018 at 08:42:20 UTC, rikki cattermole wrote: It's called integer promotion and it originates from C. And yes C++ does have such support in some variant (I really don't feel like comparing the two). And I should do? Always use "cast" operator when I operate not with ints?

Re: ushort + ushort = int?

2018-08-20 Thread rikki cattermole via Digitalmars-d-learn
On 20/08/2018 8:34 PM, Andrey wrote: Hello, Here is a code that you can execute using online compiler https://run.dlang.io/: import std.stdio; void main() {    ushort first = 5;    ushort second = 1000;    ushort result = first + second;    writeln(result); } I hae this error: onlineapp.d

ushort + ushort = int?

2018-08-20 Thread Andrey via Digitalmars-d-learn
Hello, Here is a code that you can execute using online compiler https://run.dlang.io/: import std.stdio; void main() { ushort first = 5; ushort second = 1000; ushort result = first + second; writeln(result); } I hae this error: onlineapp.d(7): Error: cannot implicitly convert