Estoy haciendo un programa para comprobar el tamaño y signo admitido por las variables en c y su funcionalidad en cada version de windows y arquitectura. Todo empezo porque cuando intento usar por ejemplo double se queda calculando indefinidamente.
Este es el programa:
Código
#include <stdio.h> #include <stdlib.h> void main(){ char tipo_char=1, tipo_char_max=1; // -128 a 128 unsigned char tipo_unsigned_char=1, tipo_unsigned_char_max=1; // 0 a 256 short int tipo_short_int=1, tipo_short_int_max=1; // -32768 a 32767 unsigned short int tipo_unsigned_short_int=1, tipo_unsigned_short_int_max=1; // 0 a 65 535 long int tipo_long_int=1, tipo_long_int_max=1; //-2 147 483 648 a 2 147 483 647 unsigned long int tipo_unsigned_long_int=1, tipo_unsigned_long_int_max=1; // 0 a 4 294 967 295 int tipo_int=1, tipo_int_max=1; //-2 147 483 648 a 2 147 483 647 unsigned int tipo_unsigned_int=1, tipo_unsigned_int_max=1; // 0 a 4 294 967 295 double tipo_double=1, tipo_double_max=1; // 18 446 744 073 709 551 616 float tipo_float=1, tipo_float_max=1; // 18 446 744 073 709 551 616 while(tipo_char>0){ tipo_char_max=tipo_char+(tipo_char-1); tipo_char=tipo_char*2; //printf("La variable char admite como maximo: %i \n\n",tipo_char); } printf("La variable char admite numeros entre: %i y %i \n\n",tipo_char,tipo_char_max); while(tipo_unsigned_char>0){ tipo_unsigned_char_max=tipo_unsigned_char+(tipo_unsigned_char-1); tipo_unsigned_char=tipo_unsigned_char*2; } printf("La variable unsigned char admite numeros entre: %i y %i \n\n",tipo_unsigned_char,tipo_unsigned_char_max); while(tipo_short_int>0){ tipo_short_int_max=tipo_short_int+(tipo_short_int-1); tipo_short_int=tipo_short_int*2; } printf("La variable short int admite numeros entre: %i y %i \n\n",tipo_short_int,tipo_short_int_max); while(tipo_unsigned_short_int>0){ tipo_unsigned_short_int_max=tipo_unsigned_short_int+(tipo_unsigned_short_int-1); tipo_unsigned_short_int=tipo_unsigned_short_int*2; //printf("La variable admite como maximo: %i \n\n",tipo_unsigned_short_int); } printf("La variable unsigned short int admite numeros entre: %i y %i \n\n",tipo_unsigned_short_int,tipo_unsigned_short_int_max); while(tipo_long_int>0){ tipo_long_int_max=tipo_long_int+(tipo_long_int-1); tipo_long_int=tipo_long_int*2; //printf("La variable admite como maximo: %i \n\n",tipo_long_int); } printf("La variable long int admite numeros entre: %i y %i \n\n",tipo_long_int,tipo_long_int_max); while(tipo_unsigned_long_int>0){ tipo_unsigned_long_int_max=tipo_unsigned_long_int+(tipo_unsigned_long_int-1); tipo_unsigned_long_int=tipo_unsigned_long_int*2; //printf("La variable admite como maximo: %i \n\n",tipo_unsigned_long_int); } printf("La variable unsigned long int admite numeros entre: %u y %u \n\n",tipo_unsigned_long_int,tipo_unsigned_long_int_max); while(tipo_int>0){ tipo_int_max=tipo_int+(tipo_int-1); tipo_int=tipo_int*2; //printf("La variable admite como maximo: %i \n\n",tipo_long_int); } printf("La variable int admite numeros entre: %i y %i \n\n",tipo_int,tipo_int_max); while(tipo_unsigned_int>0){ tipo_unsigned_int_max=tipo_unsigned_int+(tipo_unsigned_int-1); tipo_unsigned_int=tipo_unsigned_int*2; //printf("La variable admite como maximo: %i \n\n",tipo_unsigned_int); } printf("La variable unsigned int admite numeros entre: %u y %u \n\n",tipo_unsigned_int,tipo_unsigned_int_max); while(tipo_float>0){ tipo_float_max=tipo_float+(tipo_float-1); tipo_float=tipo_float*2; //printf("La variable admite como maximo: %i \n\n",tipo_float); } //printf("La variable float admite numeros entre: %4.2f y %4.2f \n\n",tipo_float,tipo_float_max); while(tipo_double>0){ tipo_double_max=tipo_double+(tipo_double-1); tipo_double=tipo_double*2; //printf("La variable admite como maximo: %i \n\n",tipo_double); } //tipo_double=18446744073709551616; //printf("La variable double admite numeros entre: %4.2f y %4.2f \n\n",tipo_double,tipo_double_max); system("pause"); }
Y este el resultado:
Citar
La variable char admite numeros entre: -128 y 127
La variable unsigned char admite numeros entre: 0 y 255
La variable short int admite numeros entre: -32768 y 32767
La variable unsigned short int admite numeros entre: 0 y 65535
La variable long int admite numeros entre: -2147483648 y 2147483647
La variable unsigned long int admite numeros entre: 0 y 4294967295
La variable int admite numeros entre: -2147483648 y 2147483647
La variable unsigned int admite numeros entre: 0 y 4294967295
_
La variable unsigned char admite numeros entre: 0 y 255
La variable short int admite numeros entre: -32768 y 32767
La variable unsigned short int admite numeros entre: 0 y 65535
La variable long int admite numeros entre: -2147483648 y 2147483647
La variable unsigned long int admite numeros entre: 0 y 4294967295
La variable int admite numeros entre: -2147483648 y 2147483647
La variable unsigned int admite numeros entre: 0 y 4294967295
_
Y tanto el tipo double como float se queda ahi trabajando pero no termina ni en varios minutos.
El ordenador es un i5, 8GB de RAM. El SO Win7 64bits. El compilador minGW64 gcc.exe. El editor Notepad++.
Que puede fallar para que double y float no me den el resultado esperado?