NO

Author Topic: Compiler Bug, Pelles C V8.00 RC3 64-bit, simple example included  (Read 1727 times)

RichieL

  • Guest
The following program will print "true" with optimization turned off, and "false" when optimization is set to "Maximize Speed", if you input 0 when it runs:

Code: [Select]
#include <stdio.h>
int main(int argc, char *argv[])
{
struct foo
    {
unsigned char a;
unsigned char b;
};
#define Civility(X) ((int)X.a * 100 + (int)X.b)

struct foo Ralf[2]   = {{1,14}, {0, 0}};
struct foo baboon[2] = {{3,13}, {0, 0}};
int        j;

scanf("%d", &j);
    printf((Civility(Ralf[j]) < Civility(baboon[j])) ? "true\n" : "false\n");
}
The correct answer is "true" - Civility(Ralf[j]) < Civility(baboon[j]) for all j.

The problem appears to be that despite the explicit casts to int in the conditional expression, the compiler generates byte arithmetic and a byte compare with optimiztion on, and does byte-to-int conversions with optimization off. If I read the C specification correctly, the "usual arithmetic conversions" should cause byte-to-int conversions even in the absence of the explicit casts.

I have not tested this on the 32-bit version of RC3. The 32-bit version of V7.00 does 32-bit compares even with optimizations turned on.

        Richie

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Compiler Bug, Pelles C V8.00 RC3 64-bit, simple example included
« Reply #1 on: May 11, 2014, 12:27:20 PM »
OK, I will look at it.
/Pelle