![](smile.gif)
H.E.R.E.. AboUt bits and sizeof message
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..
![](smile.gif)
October 17, 2003 07:27 AM
> 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![](wink.gif)
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
CHAR_BITS (from limits.h)
> question.2 += i want to send a variable but i dont know how big it may be ..
it depends
![](wink.gif)
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
What is that about handling signed values "manually"? First I heard of it, and can''t see why you''d need to. Please explain.
October 17, 2003 11:01 AM
quote:t
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
That''s simply not true.
the only thing the standard says is that:
sizeof(char) == 1
sizeof(char)<=sizeof(short)<=sizeof(int)<=sizeof(long)
October 17, 2003 11:15 AM
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
Popular Topics
Advertisement
Recommended Tutorials
Advertisement