# size of a byte and int?

#### Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

•  Subject
• Author
• Posted on
Hi All,

Is that true that size of a byte not necessarily 8-bit?
What the std. says? If that true, then what will the size of an int,
i mean what sizeof(int) should return?

On my machine sizeof(char) == sizeof(int).
TMS320C5402 DSP (with 16-bit word size).
both returns one. So, it holds true.

But my interpretation is :
Size of int,float etc is specified in terms of bytes, not bits...which is a
standard i.e int -> 2 bytes, char -> 1 byte etc... now, actual size of these
depends up on no. of bits in a byte... which is implementation defined. So,
if we say on a machine its defined 1 byte = 8 bits then size(char) = 1byte =
8 bits size(int) = 2 bytes = 16 bits...
but on other machine 1 byte = 16 bits the size(char) = 1byte = 16 bits and
Size(Int) =2 bytes= 32 bits. In no case, it can be same for both char & int.

-Neo

Re: size of a byte and int?

Width is measured in bits.
Size is measured in bytes.

--
pete

Re: size of a byte and int?

O'kay! What does int and char (data types in C) are measured in?
-Neo

Re: size of a byte and int?

Bytes or bits, depending on whether you want size or width.

sizeof(char) is 1, by definition.

A char comprises CHAR_BIT bits. CHAR_BIT is defined in <limits.h>
and its value can vary from one implementation to the next, but
it can be no lower than 8.

sizeof(int) is at least 16 bits wide. Therefore, it must be
at least (16 + CHAR_BIT - 1) / CHAR_BIT bytes in size (ignoring
any remainder).

int must be able to represent all values in the range -32767 to +32767.

Re: size of a byte and int?

Could be 2 on some DSPs (IIRC TI's).

--
42Bastian
Do not email to snipped-for-privacy@yahoo.com, it's a spam-only account :-)
We've slightly trimmed the long signature. Click to see the full one.
Re: size of a byte and int?

No, it can't. By _definition_, sizeof(chat) is 1. This is stated in the
C standard.

--
Paul Black                        mailto: snipped-for-privacy@oxsemi.com
Oxford Semiconductor Ltd          http://www.oxsemi.com
We've slightly trimmed the long signature. Click to see the full one.
Re: size of a byte and int?

No, sizeof(char) is 1 even on DSP's that cannot access smaller than 16-bit
data.  In the case of the TMS320F24x, sizeof(char) = sizeof(int), with
both being 16-bit.  Makes the chip a real pain.

Re: size of a byte and int?

Mmm... yes, but, beware:
sizeof(char) = 1;
sizeof('c') = 1; // In C++
sizeof('c') = sizeof(int); /* In C */

Re: size of a byte and int?

The only inconvenience I can think of is dealing with "packed"
character arrays.
T

Re: size of a byte and int?

The only nuisance, in C, is that it is not so easy to guarantee
that EOF cannot appear in a char stream.  Recall that the char
reading routines return an int, which may contain the (positive)
value of an unsigned char, or some negative value, defined as EOF.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on
We've slightly trimmed the long signature. Click to see the full one.
Re: size of a byte and int?
In practice, though, such streams would almost always be files of 8-bit
characters - even if the type happens to be wider. Of course, in
theory, you're right, that could be a portability concern.

I was referring above to being unable to directly address 8 bit data
(packed strings, or blocks read from such an 8 bit packed file), and
requiring shift (or swap) and mask operations to do so.

Re: size of a byte and int?

Please desist from publishing these orphaned quoteless articles.
There is no 'above' to which to refer.  The google view of a
newsgroup is sadly distorted from reality, as is their foul posting
interface.  See my sig below for a partial cure.  Better yet, get a
real newsreader.  (Netscape, Thunderbird, Xnews all come to mind.
Xnews is only for Windoze)

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on
We've slightly trimmed the long signature. Click to see the full one.
Re: size of a byte and int?

Groups is now incompatible with my habits. Thanks for the headsup, I'll
try to remember to take the long route through their interface in
future, which allows correct quoting.
In this case the context of the posting was fairly obvious.

--Toby

Re: size of a byte and int?

Nope.  sizeof  (char) is 1.  It doesn't matter if the char has
8, 16, or 32 bits.

--
Grant Edwards                   grante             Yow!  does your DRESSING
at               ROOM have enough ASPARAGUS?
We've slightly trimmed the long signature. Click to see the full one.
Re: size of a byte and int?
snipped-for-privacy@yahoo.com (42Bastian Schick) wrote in

No, but maybe you're thinking of CHAR_BITS?

--
- Mark ->
--

Re: size of a byte and int?

No, but maybe he's thinking of CHAR_BIT.

Re: size of a byte and int?
yeah, I think I get to know them, too.
Thank you.

Re: size of a byte and int?

???? Know what ?

--
42Bastian
Do not email to snipped-for-privacy@yahoo.com, it's a spam-only account :-)
We've slightly trimmed the long signature. Click to see the full one.
Re: size of a byte and int?

Yes.

It says that a byte is CHAR_BIT bits in width, where CHAR_BIT >= 8.

It will be whatever it is on a given implementation.

No. Integers and floats are specified in terms of value limits
and precision. The minimum range that a signed int must be able
to represent is -32767..32767. Mathematics dictate that this
requires at least 16 bits (including a sign bit.) Thus, an
int will require _at least_ as many bytes as is required to
store 16-bits.

Google for N869 and read the last public draft of the C99 standard.
--
Peter

Re: size of a byte and int?
On Tue, 25 Jan 2005 13:11:04 +0530, "Neo"

I think common sense is that a byte is nowadays 8 bit.

Don't mix byte with char ! I don't think there is a std defining the
width of a byte.

^^^
That's it, they speak of words avoiding the term byte.

A reason, to define __u8,__u16,__u32 etc. (or the like) depending on
the cpu and/or compiler.
--
42Bastian
Do not email to snipped-for-privacy@yahoo.com, it's a spam-only account :-)
We've slightly trimmed the long signature. Click to see the full one.