TODOPIC
Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: migsantiago en 08 de Mayo de 2014, 23:54:12
-
Hola
Usando XC8 v1.30 en versión free me está saliendo un glitch medio raro. Primero declaro un tipo de 24 bits sin signo, de acuerdo a la datasheet del compilador es como sigue:
typedef unsigned short long uint24_t;
Short + long, quién lo pensaría.
Luego, defino un tamaño en un define... nada del otro mundo...
#define SIM_FTP_AUDIO_1_FULL_SIZE (128 * 1024)
Creo una variable con mi typedef...
uint24_t index = 0;
Y cuando hago uso de ella en una comparación...
while(index < SIM_FTP_AUDIO_1_FULL_SIZE)
El compilador se pone loco :z) y me dice:
sim908.c:800: warning: (765) degenerate unsigned comparison
Leyendo la ayuda de Microchip me dice que...
(765) degenerate unsigned comparison (Code Generator)
There is a comparison of an unsigned value with zero, which will always be true or
false, e.g.:
unsigned char c;
if(c >= 0)
will always be true, because an unsigned value can never be less than zero.
Pero eso es falso, estoy comparando con algo diferente a cero.
¿Alguien le ha dado la vuelta a este glitch raro?
Gracias! :mrgreen:
-
Hola
yo probaría haciendo un cast en el define de SIM_FTP_AUDIO1_FULL_SIZE
#define SIM_FTP_AUDIO_1_FULL_SIZE (uint24_t) 128 * (uint24_t) 1024
para que concuerden los tamaños de palabra
-
Coloca al defien el post fijo UL
algo asi
#define SIM_FTP_AUDIO_1_FULL_SIZE (128UL * 1024UL)
Saludos !
-
Hola, en efecto el casting funcionó OK. Equivale a UL también. Gracias Pablo y Richi.
#define SIM_FTP_AUDIO_1_FULL_SIZE (uint24_t)((uint24_t)128 * (uint24_t)1024)
Lo curioso es que antes yo había probado un casting sencillo y no funciona.
#define SIM_FTP_AUDIO_1_FULL_SIZE (uint24_t)(128 * 1024)
Con el casting súper explícito es como sí funcionó jeje
Debe ser porque los enteros que metí al define se crean como int16_t y pues al ser el uint24_t un tipo raro e interactuar con él, el compilador se pone loco.
Saludos
-
Mirando el manual del XC8, en la página 215, explica que es lo que pasa:
The type and conversion of numeric values in the preprocessor domain is the same as
in the C domain. Preprocessor values do not have a type, but acquire one as soon as
they are converted by the preprocessor. Expressions can overflow their allocated type
in the same way that C expressions can overflow.
Overflow can be avoided by using a constant suffix. For example, an L after the number
indicates it should be interpreted as a long once converted.
So, for example
#define MAX 1000*1000
and
#define MAX 1000*1000L
will define the values 0x4240 and 0xF4240, respectively.
Saludos
-
Lección aprendida, usaré más los post fijos en el futuro. Gracias Pablo. :mrgreen: