NO

Author Topic: 2^64 overflow in constant in Pelles C IDE  (Read 2468 times)

FruitDealer

  • Guest
2^64 overflow in constant in Pelles C IDE
« on: August 29, 2014, 08:40:44 AM »
I have value = 18446744073709551616, which is 2^64 and I am storing it in "unsigned long long" constant. But compiler show me "warning #2072: Overflow in constant '18446744073709551616'". How can I store this value properly?

p.s. when I compile this program in VS2013, my program works properly, but in Pelles-C it doesn't work right.
« Last Edit: August 29, 2014, 08:42:33 AM by FruitDealer »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: 2^64 overflow in constant in Pelles C IDE
« Reply #1 on: August 29, 2014, 09:39:55 AM »
I have value = 18446744073709551616, which is 2^64 and I am storing it in "unsigned long long" constant. But compiler show me "warning #2072: Overflow in constant '18446744073709551616'". How can I store this value properly?
PellesC compiler is right, you are overflowing the variable.
An "unsigned long long" max value is  0xFFFF FFFF FFFF FFFF = 2^64-1 = 18446744073709,551615.
2^64 = 0X1 0000 0000 0000 0000 and requires 65 bits.
You can use 128bits math if you really need these values.
p.s. when I compile this program in VS2013, my program works properly, but in Pelles-C it doesn't work right.
That's not clear   ???
Maybe it uses 128 bits, or simply truncates assignement.
Try to assigning 0 to your variable, if your program works in PellesC means that VS2013 truncates values (and that your code need some corrections... ;)).
« Last Edit: August 29, 2014, 09:51:53 AM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide