NO

Author Topic: Optimization ignores integer promotion rules  (Read 2158 times)

neo313

  • Guest
Optimization ignores integer promotion rules
« on: June 05, 2014, 03:19:49 PM »
Any level of optimization will ignore integer promotion rules, which say ( I'm paraphrasing )that when using comparison( == ) any integer with a rank lower than int will get promoted to int if it can represent all values (C Standard 2011:  6.3.1.1) .

No printf() should be reachable in the code.

Code: [Select]

#include <stdio.h>

int main( void )
{
signed char a = -1;
unsigned char b = a;

if( b == a ) //both promoted to int, result is 255 == -1, which yields false
printf("unreachable\n") ;

if( b == -1 )
printf("unreachable\n") ;

if( ( unsigned char )a == a )
printf("unreachable\n") ;

if( ( int )b == ( int )-1 ) //even if explicitly cast to int
printf("unreachable\n") ;


short sa = -1;
unsigned short sb = sa;

if( sb == sa )
printf("unreachable\n") ;

if( sb == -1 )
printf("unreachable\n") ;

if( ( unsigned short )sa == sa )
printf("unreachable\n") ;

    return 0;
}


I'm using version 8.00.11 RC#4, 32bit , Windows 7

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Optimization ignores integer promotion rules
« Reply #1 on: June 06, 2014, 10:36:27 AM »
I will look at it...
/Pelle