Moritz Warning wrote:
<snip>
ubyte z = 5;
int x = -z; // x now is 251
int y = -1 * z; // y is now -5

Indeed, I've just looked at the spec, and it appears that the promotion of all smaller integer types to int/uint applies only to binary operations. Why?

It even arguably breaks the "looks like C, acts like C" principle (which I thought was the reason behind these promotions in D):
----------
#include <stdio.h>

int main() {
    unsigned char z = 5;
    int x = -z; // x now is 251
    int y = -1 * z; // y is now -5

    printf("%d %d %d\n", z, x, y);
    return 0;
}
----------
5 -5 -5
----------
(DMC 8.42n Win)

Stewart.

Reply via email to