In C, variables are promoted to unsigned int or int before operations like
adding or multiplying so that we have on ia32 PC:
 unsigned char uc1 = 0x10, uc2 = 0x10;
 printf ("0x%X\n", uc1*uc2); -> display 0x100
 unsigned short us1 = 0x1000, us2 = 0x10;
 printf ("0x%X\n", us1*us2); -> display 0x10000
That doesn't work for unsigned long long, by design we have:
 unsigned u1 = 0x10000000, u2 = 0x10;
 printf ("0x%llX\n", (unsigned long long)(u1*u2)); -> display 0x0
It "would be nice" to be able to set the size to promote operands before
operations to either int/unsigned (as now) or long long/unsigned long long
to have the intended result on lines like:
 unsigned long long ull = u1 * u2; // with previous values of u1 and u2...
Nothing else should be changed by this option, default parameter size
of printf() should still be int/unsigned, so that a line like:
 unsigned u3 = u1 * u2;
would be optimised to the same assembly instructions whatever the value
of the switch.


-- 
           Summary: option to set the "promoted" type of parameters of
                    calculus
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: etienne_lorrain at yahoo dot fr
 GCC build triplet: any
  GCC host triplet: any
GCC target triplet: any


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43162

Reply via email to