EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

size of a byte and int?

Started by Neo January 25, 2005
Neo wrote:
> "Peter Nilsson" <airia@acay.com.au> wrote in message > news:1106646608.010225.80650@z14g2000cwz.googlegroups.com...
>
>>C99 introduced the intN_t types to cater for programs which >>do rely on precise width twos complement integer types, >>however programs which make use of them are not strictly >>conforming. >> >>-- >>Peter >> > > Why not conforming?
(They are not _strictly_ conforming) Because a platform is not required to provide them. Just in case it cannot support them.
> Then why does the std. defines these?
Probably to make the interface to this functionality uniform across the subset of platforms that can support them. This is not a bad thing since code that really needs this is unlikely to ever have much use on a platform which cannot provide this. -- Thomas.
On Tue, 25 Jan 2005 09:25:50 +0000, 42Bastian Schick wrote:

>>Bytes or bits, depending on whether you want size or width. >> >>sizeof(char) is 1, by definition. > > Could be 2 on some DSPs (IIRC TI's).
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.
[F'up2 cut down --- should have been done by OP!]

In comp.arch.embedded Neo <timeless_illusion@yahoo.com> wrote:

> 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?
You cross-posted this question to two newsgroups, one of which (c.a.e) it is seriously off-topic in. Please don't do that, or if you do, at least explain why, and set a Followup-To. As is, your posting silently assumes a context that only applies to half your audience, causing all kinds of needless confusion. In the context of comp.arch.embedded, your question doesn't make much sense at all. In the context of comp.lang.c, the answers to the above are: Yes. The same. Implementation-defined. (In that order). Your confusion seems to come from the fact that you don't realize that sizeof(int), too, is implementation-defined (within limitations set up by the standard on the range of values an int must at least be able to hold). In theory, an implementation could have, say CHAR_BITS == 13 sizeof(short) == 2 sizeof(int) == 3 sizeof(long) == 5 sizeof(float) == 7 sizeof(double) == 9 just for the perverse fun of it. -- Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.
David wrote:
> On Tue, 25 Jan 2005 09:25:50 +0000, 42Bastian Schick wrote: > > >>>Bytes or bits, depending on whether you want size or width. >>> >>>sizeof(char) is 1, by definition. >> >>Could be 2 on some DSPs (IIRC TI's). > > > 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. >
Mmm... yes, but, beware: sizeof(char) = 1; sizeof('c') = 1; // In C++ sizeof('c') = sizeof(int); /* In C */
On 2005-01-25, 42Bastian Schick <bastian42@yahoo.com> wrote:
>>Bytes or bits, depending on whether you want size or width. >> >>sizeof(char) is 1, by definition. > > Could be 2 on some DSPs (IIRC TI's).
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? visi.com
On 2005-01-25, 42Bastian Schick <bastian42@yahoo.com> wrote:
> On Tue, 25 Jan 2005 13:11:04 +0530, "Neo" ><timeless_illusion@yahoo.com> wrote: > >>Hi All, >> >>Is that true that size of a byte not necessarily 8-bit? > > I think common sense is that a byte is nowadays 8 bit.
Common sense is often wrong. As yours seems to be in this case. I've worked on architectures where a byte (a-la "C") was 32 bits.
> That's it, they speak of words avoiding the term byte.
The OP is asking about C. In C, 'byte' has a very specific definition. -- Grant Edwards grante Yow! Yow! I like my new at DENTIST... visi.com
bastian42@yahoo.com (42Bastian Schick) wrote in
news:41f61067.102320849@news.individual.de: 

>>Bytes or bits, depending on whether you want size or width. >> >>sizeof(char) is 1, by definition. > > Could be 2 on some DSPs (IIRC TI's).
No, but maybe you're thinking of CHAR_BITS? -- - Mark -> --
bastian42@yahoo.com (42Bastian Schick) wrote in
news:41f610df.102440762@news.individual.de: 

> On Tue, 25 Jan 2005 13:11:04 +0530, "Neo" > <timeless_illusion@yahoo.com> wrote: > >>Hi All, >> >>Is that true that size of a byte not necessarily 8-bit? > > I think common sense is that a byte is nowadays 8 bit. > > >>What the std. says? If that true, then what will the size of an int, > > Don't mix byte with char ! I don't think there is a std defining the > width of a byte. > > >>i mean what sizeof(int) should return? >> >>On my machine sizeof(char) == sizeof(int). >>TMS320C5402 DSP (with 16-bit word size). > ^^^ > 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.
Leading underscores are for the implementation, not application programs. -- - Mark -> --
On 25 Jan 2005 15:38:47 GMT, Grant Edwards <grante@visi.com> wrote:

>On 2005-01-25, 42Bastian Schick <bastian42@yahoo.com> wrote: >> On Tue, 25 Jan 2005 13:11:04 +0530, "Neo" >><timeless_illusion@yahoo.com> wrote: >> >>>Hi All, >>> >>>Is that true that size of a byte not necessarily 8-bit? >> >> I think common sense is that a byte is nowadays 8 bit. > >Common sense is often wrong. As yours seems to be in this >case. I've worked on architectures where a byte (a-la "C") was >32 bits. > >> That's it, they speak of words avoiding the term byte. > >The OP is asking about C. In C, 'byte' has a very specific >definition.
A byte is ALWAYS 8 bits. A word is usually the larger of 16 or whatever the width of the processor bus.
On 2005-01-25, Mike Harrison <mike@whitewing.co.uk> wrote:
> On 25 Jan 2005 15:38:47 GMT, Grant Edwards <grante@visi.com> wrote:
>>>>Is that true that size of a byte not necessarily 8-bit? >>> >>> I think common sense is that a byte is nowadays 8 bit. >> >>Common sense is often wrong. As yours seems to be in this >>case. I've worked on architectures where a byte (a-la "C") was >>32 bits. >> >>> That's it, they speak of words avoiding the term byte. >> >>The OP is asking about C. In C, 'byte' has a very specific >>definition. > > A byte is ALWAYS 8 bits.
Not in C. In C, a byte is the smallest addressible unit of memory.
> A word is usually the larger of 16 or whatever the width of > the processor bus.
I don't believe that "word" has a definition in C. -- Grant Edwards grante Yow! Hey, LOOK!! A pair of at SIZE 9 CAPRI PANTS!! They visi.com probably belong to SAMMY DAVIS, JR.!!

The 2024 Embedded Online Conference