Advertisement

H.E.R.E.. AboUt bits and sizeof message

Started by October 17, 2003 06:36 AM
3 comments, last by Wickeeed 21 years, 3 months ago
Hi to all, i have some very noob questions for you question.1 = how much bits is (sizeof(1)); ?? question.2 = what is a good size for a variable (to send) ?? question.2 += i want to send a variable but i dont know how big it may be .. i hope you understand what i mean..
> question.1 = how much bits is (sizeof(1));
CHAR_BITS (from limits.h)

> question.2 += i want to send a variable but i dont know how big it may be ..
it depends
don''t use sizeof(type) directly, use numeric constants instead.
don''t forget to fix the byte order of shorts/longs (ntohl...).
and you''ll have to handle singed values manually.

unsigned char: 1, guaranteed to be atleast 8 bits
unsigned short: 2, guaranteed to be atleast 16 bits
unsigned long: 4, guaranteed to be atleast 32 bits
Advertisement
What is that about handling signed values "manually"? First I heard of it, and can''t see why you''d need to. Please explain.
quote:

unsigned char: 1, guaranteed to be atleast 8 bits
unsigned short: 2, guaranteed to be atleast 16 bits
unsigned long: 4, guaranteed to be atleast 32 bits

t

That''s simply not true.
the only thing the standard says is that:
sizeof(char) == 1
sizeof(char)<=sizeof(short)<=sizeof(int)<=sizeof(long)

Try looking for a stddef include -- it often includes such things as uint8_t, int32_t, etc

This topic is closed to new replies.

Advertisement