tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Re: global 64-bit variables initialization


From: Masha Rabinovich
Subject: [Tinycc-devel] Re: global 64-bit variables initialization
Date: Thu, 20 Nov 2008 08:50:22 +0100

Hello

Seems the problem is not only with 'long long' but with any casting performed outside of code blocks

int a = 2.0 ? 0 : 1;
int b = (_Bool)2.0;
int c = !2.0;
int d = 2.0;
int e = (char)500;

int main()
{
  printf("%d %d %d %d %d\n", a, b, c, d, e);
}

GCC output: 0 1 0 2 -12

TCC output: 1 0 1 0 500


On Wed, Nov 19, 2008 at 1:54 AM, Masha Rabinovich <address@hidden> wrote:
/*
TCC bug:
  only lower 32 bit of 64-bit global variables are properly initialized,
  higher 32 bit have garbage

Environment:
  Win2000

TCC version:
  version 2008-09-15 from http://repo.or.cz/w/tinycc.git
  version 0.9.24 from http://bellard.org/tcc/

Expected output:
0000000000000000
0000000000000000
0000000000000000

Received output:
0000000000020000
0000000000000000
0000000028234700
*/

#include <stdio.h>

struct S1
{
  unsigned long long a, b;
};

struct S1 xx = {0};

unsigned long long y = 0;

int main()
{
  printf("%02X", ((unsigned char*)&xx.a)[0]);
  printf("%02X", ((unsigned char*)&xx.a)[1]);
  printf("%02X", ((unsigned char*)&xx.a)[2]);
  printf("%02X", ((unsigned char*)&xx.a)[3]);
  printf("%02X", ((unsigned char*)&xx.a)[4]);
  printf("%02X", ((unsigned char*)&xx.a)[5]);
  printf("%02X", ((unsigned char*)&xx.a)[6]);
  printf("%02X", ((unsigned char*)&xx.a)[7]);
  printf("\n");

  printf("%02X", ((unsigned char*)&xx.b)[0]);
  printf("%02X", ((unsigned char*)&xx.b)[1]);
  printf("%02X", ((unsigned char*)&xx.b)[2]);
  printf("%02X", ((unsigned char*)&xx.b)[3]);
  printf("%02X", ((unsigned char*)&xx.b)[4]);
  printf("%02X", ((unsigned char*)&xx.b)[5]);
  printf("%02X", ((unsigned char*)&xx.b)[6]);
  printf("%02X", ((unsigned char*)&xx.b)[7]);
  printf("\n");

  printf("%02X", ((unsigned char*)&y)[0]);
  printf("%02X", ((unsigned char*)&y)[1]);
  printf("%02X", ((unsigned char*)&y)[2]);
  printf("%02X", ((unsigned char*)&y)[3]);
  printf("%02X", ((unsigned char*)&y)[4]);
  printf("%02X", ((unsigned char*)&y)[5]);
  printf("%02X", ((unsigned char*)&y)[6]);
  printf("%02X", ((unsigned char*)&y)[7]);
  printf("\n");
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]