473,670 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Padding bits and char, unsigned char, signed char

Under C95:

Is it guaranteed that char, unsigned char, signed char have no padding bits?
Mar 28 '08 #1
4 3306
Ioannis Vranos wrote:
>
Under C95: Is it guaranteed that char, unsigned char, signed
char have no padding bits?
unsigned char, yes. The others by implication. I haven't checked
the standard. Why don't you?

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Mar 28 '08 #2
On Fri, 28 Mar 2008 16:01:54 -0500, CBFalconer wrote:
Ioannis Vranos wrote:
>Under C95: Is it guaranteed that char, unsigned char, signed char have
no padding bits?
Just a note: padding bits are a concept introduced in the standard in
C99; C90/C95 left much more unspecified about the representation of
integer types.
unsigned char, yes.
Where is this guarantee made? In C99, 5.2.4.2.1 makes it as clear as it
can: "The value UCHAR_MAX shall equal 2^CHAR_BIT - 1." I don't have a
copy of an older standard. Does it make the same guarantee?
The others by implication.
How so? What's preventing a signed integer type and its corresponding
unsigned type from having a different number of padding bits?
Mar 28 '08 #3
Harald van =?UTF-8?b?RMSzaw==?= wrote:
>
On Fri, 28 Mar 2008 16:01:54 -0500, CBFalconer wrote:
Ioannis Vranos wrote:
Under C95: Is it guaranteed that char,
unsigned char, signed char have no padding bits?

Just a note: padding bits are a concept introduced in the standard in
C99; C90/C95 left much more unspecified about the representation of
integer types.
unsigned char, yes.

Where is this guarantee made?
In C99, 5.2.4.2.1 makes it as clear as it
can: "The value UCHAR_MAX shall equal 2^CHAR_BIT - 1." I don't have a
copy of an older standard. Does it make the same guarantee?
It doesn't.
There's really nothing about padding in the "basic types" in C90.
The others by implication.

How so? What's preventing a signed integer type and its corresponding
unsigned type from having a different number of padding bits?
I think he meant char and signed char, but even then I disagree.

As far as I know, signed char can have padding bits.

--
pete
Mar 28 '08 #4
Harald van Dijk <tr*****@gmail. comwrites:
On Fri, 28 Mar 2008 16:01:54 -0500, CBFalconer wrote:
>Ioannis Vranos wrote:
>>Under C95: Is it guaranteed that char, unsigned char, signed char have
no padding bits?

Just a note: padding bits are a concept introduced in the standard in
C99; C90/C95 left much more unspecified about the representation of
integer types.
>unsigned char, yes.

Where is this guarantee made? In C99, 5.2.4.2.1 makes it as clear as it
can: "The value UCHAR_MAX shall equal 2^CHAR_BIT - 1."
But that alone is not enough, is it? The clearest statement comes
later in 6.2.6. p1: "For unsigned integer types other than unsigned
char, the bits of the object representation shall be divided into two
groups: value bits and padding bits (there need not be any of the
latter).". So, unsigned char has only value bits.

--
Ben.
Mar 28 '08 #5

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

Similar topics

11
2567
by: Steve | last post by:
Hi, i know this is an old question (sorry) but its a different problem, i need to write a binary file as follows 00000011 00000000 00000000 00000101 00000000 11111111
5
403
by: Stephen Mayes | last post by:
I this helloworld portable? I am vaguely aware of something called "structure padding" and wonder if it could affect this program since the struct only contains chars. #include <stdio.h> #include <stdlib.h> #include <string.h> int main (void) {
9
4821
by: edware | last post by:
I want to read header data from a image file, and I have a struct that represent this header. But it seems like my compiler pads the data, resulting that my fread() call won't put the right things in the right place. The struct starts like this: struct header { char magic; /* 2 bytes */
40
2162
by: Allan M. Bruce | last post by:
I am applying for my first jobs after completing my PhD. I have been asked by a company to go and take a C programming test to see how my C skills are. Apparantly this test is mostly finding errors in small snippets of code but I was wondering if anyone could give me tips on what kind of things I should be looking out for. The one area I dont feel confident in is how to declare arrays of pointers and initialising multi-dimensional arrays....
77
4251
by: borophyll | last post by:
As I read it, C99 states that a byte is an: "addressable 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
6
2829
by: John Messenger | last post by:
I notice that the C standard allows padding bits in both unsigned and signed integer types. Does anyone know of any real-world examples of compilers that use padding bits? -- John
9
469
by: Ioannis Vranos | last post by:
Under C++03: Is it guaranteed that char, unsigned char, signed char have no padding bits?
3
3858
by: vippstar | last post by:
Hey comp.lang.c I'm somewhat confused with bit padding. I tried searching the FAQ, but there isn't a search feature, so I used google and the search query: site:c-faq.com padding. I did not find anything relevant to bit padding, only byte padding for structs, which more or less I understand. All sections are from n1256
2
1679
by: Mihai Rusu | last post by:
Hello I am trying to figure out if the standard allows integral type representations with padding (ie value representation != object representation). A conforming implementation can have: - a 32bit int and 32bit unsigned int but have the unsigned int not use the sign bit for value representation? (so INT_MAX == UINT_MAX == 2^32-1) - a 33bit int and a 33bit unsigned int and both types have the 33th bit as padding? By reading 3.9.1 I...
0
8471
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
8903
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
8815
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
8661
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
7421
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
6216
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
5686
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1795
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.