[Issue 13387] Bug with arithmetic opertions on integer types smaller than int

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 28 00:06:39 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13387

--- Comment #1 from Uranuz <neuranuz at gmail.com> ---
AFAIK, in C++ the same rules used, but it don't have problems with assignment
of type *unsigned short = unsigned short + unsigned short*. So it's strange
that we have such type of problem in D. But still integer promotions are used
to, although I disagree with it.

//-------------
#include <iostream>
#include <typeinfo>

int main()
{
    unsigned short a = 5;
    unsigned short b = 3;
    unsigned short c = a + b; //This compiles

    if( typeid(a + b) == typeid(int) )
    {
        std::cout << "int" << std::endl;
    }
    else if( typeid(a + b) == typeid(unsigned short) )
    {
        std::cout << "unsigned short" << std::endl;
    }
    else if( typeid(a + b) == typeid(unsigned int) )
    {
        std::cout << "unsigned int" << std::endl;
    }

    return 0;
}
//-------------

This programme outputs:
int

--


More information about the Digitalmars-d-bugs mailing list