NO

Author Topic: automatic conversion to "long long" without warning  (Read 3146 times)

albertn

  • Guest
automatic conversion to "long long" without warning
« on: March 27, 2007, 12:25:03 PM »
Hello!

Thanks for a nice C compiler. I like it!

Here's a small minor bug:

printf("%lld \n", 4000000000);
returns
4000000000
-> *wrong: 4000000000 is the binary 32 bit pattern "11101110011010110010100000000000" (and not a "long long"!) *

At least a warning would be nice!!  ;)



Code: [Select]
#include <stdio.h>

int main(void)
{
    int a = 4000000000;

    printf("%lld \n", a);
    /* output same as lcc-win32, different from gcc. I think the standard (C99) leaves this open to ones implementation!??? */

    printf("%d \n", 4000000000);
    /* correct */

    printf("%lld \n", 4000000000);
    /* PROBLEM */
    /* 4000000000 is the binary 32 bit pattern "11101110011010110010100000000000" (*not* "long long", *not* unsigned)
       At least a warning would be good */

    return 0;
}

Kind regards,
Albert

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: automatic conversion to "long long" without warning
« Reply #1 on: March 28, 2007, 05:07:35 PM »
printf("%lld \n", 4000000000);
returns
4000000000
-> *wrong: 4000000000 is the binary 32 bit pattern "11101110011010110010100000000000" (and not a "long long"!) *
4000000000 has no suffix, is not representable as an int or long int, so type should be long long int (as I understand the C99 standard). I can't see the problem here.

At least a warning would be nice!!  ;)
An extra warning for the case printf("%d \n", 4000000000) would be nice, but adding compiler code for matching various formatting strings to it's arguments is a lot of work, and a royal pain. I doubt it will happen (anytime soon, at least).
/Pelle