N. Coesel wrote:

At 19:38 10-08-05 +0200, you wrote:
N. Coesel wrote :

Just a thought that pops into my mind: Is "long long int" a valid type? If

you want a 64 bit number, the proper type is "long long". I would not rely
on the "int" type since the size of it depends on the architecture.


long long
signed long long
long long int
signed long long int

all design the same type (whose size is implementation-dependent).

No, a long is always 32 bit and a long long is always 64 bit; both are
implementation independant.

Anyway, I have used the long long type on MSP430 without any problems.

Nico Coesel
Wrong. The lengths of these integers are largely implementation dependant. The only thing the specs say is these names should imply minimum lengths. I think the lengths are:
   short is at least 16 bits
   long is at least 32 bits
   long long is at least 64 bits
int is something natural for machine (although most 64 bit machines make an int a 32 bit number).

64 bit Linux machines, for example, obey the C spec by using:
   short is 16 bits
   long is 64 bits
   long long is 64 bits
   int is 32 bits

mspgcc uses:
   short is 16 bits
   long is 32 bits
   long long is 64 bits
   int is 16 bits

If you want specific lengths for integers, the standards compliant method is to include <stdint.h> and use:
   int8_t or uint8_t
   int16_t or uint16_t
   int32_t or uint32_t
   int64_t or uint64_t

These are machine independant. In addition, because the relative lengths of ints and pointers varies, casting between ints and pointers should use intptr_t for the integer. This is guaranteed to be an integer capable of holding the full value of a pointer.

Regards,
Steve


Reply via email to