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

integer groesser 2^31 in C



Hi,

fuer ein Finite-Element-Programm in C, muesste ich unbedingt mehr als 2Gb
Speicher allokieren. Der Rechner hat 2Gb Speicher und 2Gb Swap.
Ich habe erst gedacht, es liegt am Kernel (CONFIG_HIGHMEM ist gesetzt),
habe jetzt aber festgestellt, dass es nicht moeglich ist in C eine Integer
zu deklarieren, die groesser als 2^31 ist.

fritzam@vwin:~/ugspeicher/test-proc> cat testint.c
#include  <stdlib.h>

int main(void){
   long long int a=2200000000;
   int b=2200000000;
   int c=2000000000;
   printf("a=%d\n",a);
   printf("b=%d\n",b);
   printf("c=%d\n",c);
   exit(0);
}
fritzam@vwin:~/ugspeicher/test-proc> gcc testint.c
testint.c: In function `main':
testint.c:4: warning: decimal constant is so large that it is unsigned
testint.c:5: warning: decimal constant is so large that it is unsigned
fritzam@vwin:~/ugspeicher/test-proc> ./a.out
a=-2094967296
b=-2094967296
c=2000000000

Hab schon mehrere Compiler ausprobiert (unter anderem auch Borland auf
Windows) und in den manpage von gcc nach optionen gesucht.
(2.4.21 hab ich auch schon getestet)

Der Kernel hat auch keine Probleme mit grossen Zahlen:
fritzam@vwin:~/ugspeicher/test-proc> echo "2^31"|bc
2147483648
fritzam@vwin:~/ugspeicher/test-proc> echo "2^32"|bc
4294967296
fritzam@vwin:~/ugspeicher/test-proc> echo "2^100"|bc
1267650600228229401496703205376

Und noch was:
fritzam@vwin:~/ugspeicher/test-proc> ulimit -a
core file size        (blocks, -c) 0
data seg size         (kbytes, -d) unlimited
file size             (blocks, -f) unlimited
max locked memory     (kbytes, -l) unlimited
max memory size       (kbytes, -m) unlimited
open files                    (-n) 1024
pipe size          (512 bytes, -p) 8
stack size            (kbytes, -s) 8192
cpu time             (seconds, -t) unlimited
max user processes            (-u) 7168
virtual memory        (kbytes, -v) unlimited

Hat jemand ne Ahnung, oder ne Idee?

Gruss Achim



Reply to: