[Top][All Lists]

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

RE: [avr-gcc-list] AVR-GCC question

From: Dave Hansen
Subject: RE: [avr-gcc-list] AVR-GCC question
Date: Mon, 23 May 2005 16:47:08 -0400

From: "Trampas" <address@hidden>

I don't think that is portable. That is I know some 16 bit processors and

It's not, but not for the reason you specify.

compilers will report an INT16 as being sizeof 1. That is sizeof for word

If sizeof(int16_t) == 1, then CHAR_BIT == 16.

addressable machines may report a char as 1 and a 16 bit variable as 1. Thus sizeof is not always number of bytes, like it is for the X86. Rather sizeof
is the number of smallest storage locations required for the variable.

sizeof _always_ reports the number of bytes. A byte does _not_ necessarily mean 8 bits (although it is always _at_least_ 8 bits).

-----Original Message-----
From: Jeff Epler [mailto:address@hidden
#include <limits.h>
#define MAX_SIGNED(x) (double)((1ull<<(CHAR_BIT * sizeof(x) - 1))-1)

Using this macro, though, the signed char -128 goes to a value below
-1.0.  I think that's the same thing your code did.


If x is a signed char, then sizeof(x) == 1. Always. Regardless of the value of x.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]