473,767 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A byte can be greater than 8 bits?

As I read it, C99 states that a byte is an:

"addressabl e unit of data storage large enough to hold any member of
the basic character
set of the execution environment" (3.6)

and that a byte must be at least 8 bits:

"The values given below shall be replaced by constant expressions
suitable for use in #if
preprocessing directives. Moreover, except for CHAR_BIT and
MB_LEN_MAX, the
following shall be replaced by expressions that have the same type as
would an
expression that is an object of the corresponding type converted
according to the integer
promotions. Their implementation-defined values shall be equal or
greater in magnitude
(absolute value) to those shown, with the same sign."

number of bits for smallest object that is not a bit-field (byte)
CHAR_BIT 8 (5.2.4.2.1)

Does this mean that a byte can be larger than 8 bits (ie CHAR_BIT >
8)? I have gotten the impression that a byte, or unsigned char, was
always 8 bits, but perhaps I was wrong. If I am not, is there
somewhere in the standard that defines a byte as always being 8 bits?

Regards,
B.

Oct 1 '07
77 4284
Philip Potter <pg*@see.sig.in validwrites:
jacob navia wrote:
>Philip Potter wrote:

[snip]

The fact that Philippe could not bring a single example
means probably that there isn't any machines where
all those terrible conditions apply!

I'm flattered that you think so! But my knowledge of particular quirks
of different C implementations is much more restricted than you
think. I have only coded for three implementations : windows, linux,
and microblaze. I don't know the ins-and-outs of these
implementations , for reasons I've already given.

I'm quite certain that others, if they wanted, could provide details
of some implementations with some of the requested features.

Besides, I did provide a single example:
>A) Systems where a byte is more than 8 bits :

DSPs are a common example here.
No, you didn't. You mentioned a range of HW where it may or may not be
true :)
Oct 1 '07 #21
jacob navia wrote On 10/01/07 09:42,:
Eric Sosman wrote:
>>jacob navia wrote:
>>>Eric Sosman wrote:

jacob navia wrote:

>Philip Potter wrote:
>
>>Give me an example of code which relies on -1 being all-bits-one.
>>
>
>#include <stdio.h>
>int maskNLowerBits( unsigned d,int n)
>{
return d & (-1 << n);
>}

Maybe Philip should have specified "code that doesn't
invoke undefined behavior." After the fix s/1/1u/ the
corrected code no longer relies on -1 being all-bits-one.
??
Is it legal to make -1u??
Unary minus applied to unsigned operand?

Yes: unary minus takes an "arithmetic type" (6.5.3.3).

Anyway, that relies still in that all bits not dropping
of the left side are all 1. And that did not change with this minor
cosmetic change!
6.5.7p4 defines the value of the result of `-1u << n'
once UINT_MAX and n are known (and if n is in range).
6.2.6.2p4 specifies that this value is represented by n
bits zero and the rest one. That is, the fixed code relies
on the guarantees of the Standard and does not rely on the
representation of `-1'.

6.5.7p4 also says that `-1 << n' gives undefined behavior.

The difference between undefined and defined seems to me
more than "minor" or "cosmetic."

--
Er*********@sun .com
Oct 1 '07 #22
Richard wrote:
Philip Potter <pg*@see.sig.in validwrites:
>Besides, I did provide a single example:
>>>>A) Systems where a byte is more than 8 bits :
DSPs are a common example here.

No, you didn't. You mentioned a range of HW where it may or may not be
true :)
Well you wanted the examples, you go find them! :P

--
Philip Potter pgp <atdoc.ic.ac. uk
Oct 1 '07 #23
Philip Potter <pg*@see.sig.in validwrites:
Richard wrote:
>Philip Potter <pg*@see.sig.in validwrites:
>>Besides, I did provide a single example:

>A) Systems where a byte is more than 8 bits :
DSPs are a common example here.

No, you didn't. You mentioned a range of HW where it may or may not be
true :)

Well you wanted the examples, you go find them! :P
Er, I was. Here. From the people who keep telling us about them all.
Oct 1 '07 #24
Philip Potter said:

<snip>
[...] Null pointers can always be set by:
foo *x = (foo *)0;
(I'm not sure if the cast is necessary)
(No, it isn't.)
even if the null pointer representation is not all-bits-zero.
Yes, even if it means the compiler doing some magic to make it all work.
I personally don't know of any non-all-bits-zero null pointer systems,
Several such machines are mentioned in the FAQ.
I can't think why you'd want to [store a function pointer in a void *].
It's not all that unusual a thing to want to do, actually, although in
practice there's always a way around it if you want it badly enough.

As for whether systems exist that lose information when copying a function
pointer value into a void *, the answer is yes, and I've got one right
here.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 1 '07 #25
Richard wrote:
Philip Potter <pg*@see.sig.in validwrites:
>Richard wrote:
>>Philip Potter <pg*@see.sig.in validwrites:
Besides, I did provide a single example:

>>A) Systems where a byte is more than 8 bits :
DSPs are a common example here.
No, you didn't. You mentioned a range of HW where it may or may not be
true :)
Well you wanted the examples, you go find them! :P

Er, I was. Here. From the people who keep telling us about them all.
Was my answer not good enough for you? It sounded to me that you had a
benevolent quest to convince people that their assumptions about the
implementation were not necessarily correct. Surely you can put some
effort into finding some? I've already given you a hint for CHAR_BIT != 8.

Meanwhile, I won't make these assumptions, and I won't have to rely on
the implementations I use to comply with these assumptions.

--
Philip Potter pgp <atdoc.ic.ac. uk
Oct 1 '07 #26
Philip Potter <pg*@see.sig.in validwrites:
Richard wrote:
>Philip Potter <pg*@see.sig.in validwrites:
>>Richard wrote:
Philip Potter <pg*@see.sig.in validwrites:
Besides, I did provide a single example:
>
>>>A) Systems where a byte is more than 8 bits :
>DSPs are a common example here.
No, you didn't. You mentioned a range of HW where it may or may not be
true :)
Well you wanted the examples, you go find them! :P

Er, I was. Here. From the people who keep telling us about them all.

Was my answer not good enough for you? It sounded to me that you had a
benevolent quest to convince people that their assumptions about the
implementation were not necessarily correct. Surely you can put some
effort into finding some? I've already given you a hint for CHAR_BIT
!= 8.
Are you joking? I asked for some examples of systems. Not vague "maybe
these". So, no, to be honest your "I think there are some DSPs" is not a
good enough example :-; Sorry. Your example is no more helpful than the
"On some systems a byte is more than 8 bits" type statements. Not
helpful to someone new who might like to see a concrete example. Maybe I
was not clear enough in which case I apologise. But it seems you don't
have any experience of any such platforms - so be it.

As for putting some "effort" in - I am. I am asking *here* where there
are a plethora of people who know a lot about such systems. I am hoping
they will give some examples of where a byte is more than 8 bits or
CHAR_BITS is more than 8. And it is a benevolent quest. I want to see
these systems and look at their specs too. It would be really good to
reference them whenever telling people their code is not standards
compliant.
>
Meanwhile, I won't make these assumptions, and I won't have to rely on
the implementations I use to comply with these assumptions.
But to do that you need to know the standard backwards. Whereas real
examples give real warnings.
Oct 1 '07 #27
Richard wrote:
Philip Potter <pg*@see.sig.in validwrites:
>Richard wrote:
>>Philip Potter <pg*@see.sig.in validwrites:

Richard wrote:
Philip Potter <pg*@see.sig.in validwrites:
>Besides, I did provide a single example:
>>
>>>>A) Systems where a byte is more than 8 bits :
>>DSPs are a common example here.
No, you didn't. You mentioned a range of HW where it may or may not be
true :)
Well you wanted the examples, you go find them! :P

Er, I was. Here. From the people who keep telling us about them all.

Was my answer not good enough for you? It sounded to me that you had a
benevolent quest to convince people that their assumptions about the
implementati on were not necessarily correct. Surely you can put some
effort into finding some? I've already given you a hint for CHAR_BIT
!= 8.

Are you joking? I asked for some examples of systems. Not vague "maybe
these". So, no, to be honest your "I think there are some DSPs" is not a
good enough example :-; Sorry. Your example is no more helpful than the
"On some systems a byte is more than 8 bits" type statements. Not
helpful to someone new who might like to see a concrete example. Maybe I
was not clear enough in which case I apologise. But it seems you don't
have any experience of any such platforms - so be it.
Concrete examples of systems with CHAR_BITS 8 have been mentioned before.
IIRC Jack Klein gave an example a few months ago. I also believe Keith
Thompson said that some Cray Vector machines he was familiar with had this
property.

Oct 1 '07 #28
Richard wrote:
Philip Potter <pg*@see.sig.in validwrites:
>Richard wrote:
>>Philip Potter <pg*@see.sig.in validwrites:

Richard wrote:
Philip Potter <pg*@see.sig.in validwrites:
>Besides, I did provide a single example:
>>
>>>>A) Systems where a byte is more than 8 bits :
>>DSPs are a common example here.
No, you didn't. You mentioned a range of HW where it may or may not be
true :)
Well you wanted the examples, you go find them! :P
Er, I was. Here. From the people who keep telling us about them all.
Was my answer not good enough for you? It sounded to me that you had a
benevolent quest to convince people that their assumptions about the
implementati on were not necessarily correct. Surely you can put some
effort into finding some? I've already given you a hint for CHAR_BIT
!= 8.

Are you joking? I asked for some examples of systems. Not vague "maybe
these". So, no, to be honest your "I think there are some DSPs" is not a
good enough example :-; Sorry. Your example is no more helpful than the
"On some systems a byte is more than 8 bits" type statements.
God helps those who help themselves:
http://groups.google.com/group/comp....rch+this+group

There is your answer, already answered several times in the history of
clc. All I did was put "DSP CHAR_BIT" into a google groups search of clc.

So no, I'm not joking. I honestly thought the information I had given
you would be enough. If I was wrong, I apologise.
Not
helpful to someone new who might like to see a concrete example. Maybe I
was not clear enough in which case I apologise. But it seems you don't
have any experience of any such platforms - so be it.

As for putting some "effort" in - I am. I am asking *here* where there
are a plethora of people who know a lot about such systems.
....and where the question has been answered a plethora of times before.
Have a look through the archives on google groups. And the FAQ (Richard
Heathfield pointed out elsethread there are some examples of
non-all-bits-zero NULLs there).
I am hoping
they will give some examples of where a byte is more than 8 bits or
CHAR_BITS is more than 8. And it is a benevolent quest. I want to see
these systems and look at their specs too. It would be really good to
reference them whenever telling people their code is not standards
compliant.
Yes, it would be very useful. I want to stress that it is not necessary,
that is, even if there is no system where you can't fit a function
pointer into a void *, you still shouldn't do it. But it is good to have
examples of where assumptions are wrong.
>Meanwhile, I won't make these assumptions, and I won't have to rely on
the implementations I use to comply with these assumptions.

But to do that you need to know the standard backwards. Whereas real
examples give real warnings.
Or heed the advice such as in the response to the OP in this thread.

--
Philip Potter pgp <atdoc.ic.ac. uk
Oct 1 '07 #29
santosh <sa*********@gm ail.comwrites:
Richard wrote:
>Philip Potter <pg*@see.sig.in validwrites:
>>Richard wrote:
Philip Potter <pg*@see.sig.in validwrites:

Richard wrote:
>Philip Potter <pg*@see.sig.in validwrites:
>>Besides , I did provide a single example:
>>>
>>>>>A) Systems where a byte is more than 8 bits :
>>>DSPs are a common example here.
>No, you didn't. You mentioned a range of HW where it may or may not be
>true :)
Well you wanted the examples, you go find them! :P

Er, I was. Here. From the people who keep telling us about them all.

Was my answer not good enough for you? It sounded to me that you had a
benevolent quest to convince people that their assumptions about the
implementatio n were not necessarily correct. Surely you can put some
effort into finding some? I've already given you a hint for CHAR_BIT
!= 8.

Are you joking? I asked for some examples of systems. Not vague "maybe
these". So, no, to be honest your "I think there are some DSPs" is not a
good enough example :-; Sorry. Your example is no more helpful than the
"On some systems a byte is more than 8 bits" type statements. Not
helpful to someone new who might like to see a concrete example. Maybe I
was not clear enough in which case I apologise. But it seems you don't
have any experience of any such platforms - so be it.

Concrete examples of systems with CHAR_BITS 8 have been mentioned before.
IIRC Jack Klein gave an example a few months ago. I also believe Keith
Thompson said that some Cray Vector machines he was familiar with had this
property.
Yes, so lets get them with links now so we can keep them. I would gladly
keep a list up to date.

As for Cray Vector machines, lets try and get a list of machines more
available to the common man but they would be a good start if we could
get a link to the specs.
Oct 1 '07 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
3272
by: w3r3w0lf | last post by:
hello! I have a following situation: I have a byte array where at a certain location are stored 4 bytes, and these should be "put" into long variable (or any other 4 byte one). ie: byte a={0x0,0x0,0xfe,0x30,0x9e,0x2,0x66,0,0} and the bytes 0xfe,0x30,0x9e,0x2 should be put into long variable which should then contain 43921662 how to achieve this?
235
11787
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could stay with C and still be able to produce Java byte code for platform independent apps. Also, old programs (with some tweaking) could be re-compiled and ported to the JVM. We have been developing such a tool over the last 2 years and currently...
16
9224
by: Samuel Thomas | last post by:
Hello Friends, I understand(could be wrong) that the smallest chunk of memory is called a word. If that is correct, that means if I am using a 32 bit OS a word is 4 bytes. So that's why the size of an int is 4 bytes. How is it that a char then gets 1 byte. Shouldn't it also get 4 bytes even though it might be able to store only 256 values? Is the OS doing some sort of trimming? Thanks
47
16566
by: Kapil Khosla | last post by:
Hi, I am trying to reverse a byte eg. 11010000 should look like 00001011 Plz note, it is not a homework problem and I do not need the c code for it. Just give me an idea how should I proceed about it. I know basic bit manipulation , shifting left, right and have done
4
1859
by: s.subbarayan | last post by:
Dear all, I would like to know the easiest efficient way to set or inject a particular value in the given word or byte?The problem is: I have to implement a function which will set a value from position "n" to "n+x" where n and x are passed dynamically,where n is start position of the bit from which i will be setting a value and x is the position where I will be finishing the setting.In short it looks like this:
33
3415
by: Benjamin M. Stocks | last post by:
Hello all, I've heard differing opinions on this and would like a definitive answer on this once and for all. If I have an array of 4 1-byte values where index 0 is the least signficant byte of a 4-byte value. Can I use the arithmatic shift operators to hide the endian-ness of the underlying processor when assembling a native 4-byte value like follows: unsigned int integerValue; unsigned char byteArray;
96
4973
by: david ullua | last post by:
I am reading "Joel on Software" these days, and am in stuck with the question of "how to calculate bitsize of a byte" which is listed as one of the basic interview questions in Joel's book. Anyone could give some ideas?I am expecting your reply. David.
14
1918
by: rsood | last post by:
Hi I'm developing a program, and naturally I want it to be as portable as possible. I need to be able to access specific numbers of bytes in it, but as far as I know, there is no keyword in the c language such as 'byte'. Is it always okay to assume that the char data type is always 1 byte, or is there some other way to be sure you are getting 1 byte that is not processor/OS dependent that is better, or is there no way to be both...
20
3529
by: quantumred | last post by:
I found the following code floating around somewhere and I'd like to get some comments. unsigned char a1= { 5,10,15,20}; unsigned char a2= { 25,30,35,40}; *(unsigned int *)a1=*(unsigned int *)a2; // now a1=a2, a1=a2, etc.
0
9571
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10009
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9838
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8835
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.