Question about iteger literals

Uranuz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 20 11:12:42 PDT 2014


> In C/C++/D if you sum a types that are smaller than int, you 
> obtain an int. D has copied C for backwards compatibility with 
> C code.
>
> Bye,
> bearophile

Is there any reasoning why this should remain unchainged? How 
could it break interface between languages? And also this code 
succesfully compiles and runs in C++.

#include <iostream>

using namespace std;

int main()
{
    unsigned short a = 15;
    unsigned short b = 10;

    unsigned short c = a + b;  //There is no problem

    cout << c << endl;

    return 0;
}

As D compiler doesn't need to compile C programme and have 
compatible operations with types. Why we still should keep this 
garbage?!

I don't know the right solution but I believe that previous 
example illustrates some contradiction in integer types system 
design or implementation.

Why we dont promote *ulong* and *long* to int? Let's also promote 
string into array of ints?! Can't believe it!


More information about the Digitalmars-d-learn mailing list