473,804 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Padding Bits

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
Feb 10 '08 #1
6 2847
John Messenger <jo*******@newc omp.netwrote:
>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?
The Burroughs B7700 has 48-bit words.
Integer numbers have a sign-and-magnitude representation, using 1 bit
for the sign and 39 bits for the magnitude; the remaining 8 bits are left
unused (floatingpoint numbers use these bits for the exponent).

See also http://home.hetnet.nl/mr_1/81/jhm.bo...nisys.htm#gene

Ike
Feb 10 '08 #2
On Sun, 10 Feb 2008 12:31:55 +0000, Ike Naar wrote:
John Messenger <jo*******@newc omp.netwrote:
>>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?

The Burroughs B7700 has 48-bit words. Integer numbers have a
sign-and-magnitude representation, using 1 bit for the sign and 39 bits
for the magnitude; the remaining 8 bits are left unused (floatingpoint
numbers use these bits for the exponent).

See also
http://home.hetnet.nl/mr_1/81/jhm.bo.../bitsandbytes/
wordsizes/unisys.htm#gene
>
Ike
The Burroughs B7700 might have 48-bit words with padding bits, but it
appears to not have a C compiler, let alone a Standard C compiler. Ernie
took these pictures (one of the Burroughs B7700) in 1981, which was about
a decade before the first C Standard came out.

http://www.eecis.udel.edu/~mader/delta/erniepics.html

Based on the lack of responses to my question, I have to conclude that
there are no real-world examples of C compilers that use padding bits, so
we never have to deal with padding bits in the real world.

--
John
Feb 11 '08 #3
John Messenger said:

<snip>
Based on the lack of responses to my question, I have to conclude that
there are no real-world examples of C compilers that use padding bits, so
we never have to deal with padding bits in the real world.
Yeah. Everything's already been invented, too, so there's no need to worry
about future implementations or architectures.

And if you'd asked instead, say, whether anyone had used any non-ASCII
character sets, and it just happened that nobody who had done so bothered
to respond to your article, would you have concluded that non-ASCII
character sets do not now and will never exist?

I have an idea for you, which will be a great time-saver. Up until now,
presumably you've written a number of programs over the course of your
career. All of those programs obviously meet a real world requirement,
otherwise you wouldn't have written them. But how about any other programs
you might consider writing? Forget it - if they had any real world
utility, you would already have written them.

Everything has been invented, all the world's a 32-bit PC running Windows,
and the world has an infinite supply of oil.

Happy days.

--
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
Feb 11 '08 #4
On Mon, 11 Feb 2008 07:38:58 +0000, Richard Heathfield wrote:
John Messenger said:

<snip>
>Based on the lack of responses to my question, I have to conclude that
there are no real-world examples of C compilers that use padding bits,
so we never have to deal with padding bits in the real world.

Yeah. Everything's already been invented, too, so there's no need to
worry about future implementations or architectures.
I should have qualified my response as saying that we *currently* do not
have to deal with padding bits in the real world. Not with gcc under
Linux, or MS VC++ in Windows, or with all of the embedded C compilers we
use (which mainly run under Windows).

Future implementations or architectures may well decide to include
padding bits in integer types, and if so, we'll have to deal with that
decision. In all likelihood, though, the next breakthrough in computer
architecture will be 128-bit integers, and they won't use any padding
bits.

The motivation for asking my question comes from having to deal with C
programmers who, unlike you and me and the other experts in this
newsgroup, don't know the least thing about padding bits in integer
types, and therefore don't know about how to deal with the ramifications
of implementing code that might be compromised by a compiler that defines
padding bits. If there are no compilers in the real world that use
padding bits in integer types, then my job of managing these people
becomes a lot easier.
And if you'd asked instead, say, whether anyone had used any non-ASCII
character sets, and it just happened that nobody who had done so
bothered to respond to your article, would you have concluded that
non-ASCII character sets do not now and will never exist?
Yes.

ASCII is the de facto standard for C code in general and source code
distribution in general. Any time one distributes source code via an
electronic medium (whether it is on a CD, or in a compressed archive such
as GZIP or ZIP or BZ or whatever, or in a simple uncompressed format,
etc.), they have committed to using a specific character encoding,
whether they are aware of it or like it or not.

You, and your companions, in fact, distribute the source code for the
examples in the book "C Unleashed" in ASCII encoding, right? By doing so,
you have conformed to the de facto use of ASCII character encoding, and
at the same time gave all of those no hope in using your source code if
they use a compiler that uses any character encoding other than ASCII.
Did you and the others who wrote "C Unleashed" include any type of
disclaimer similar to the following?

"The source code on the companion CD is stored in the ASCII encoding
format. If you use any C compiler that does not expect the ASCII encoding
format, this code will most likely not compile. Don't blame this on the C
Standard--blame it on us".

The only sure way to "distribute " portable C source code is via such
mediums as printed books or printed graphics (e.g., what you see on your
monitor when viewing web pages on The Internet, or when viewing posts on
Usenet, etc.). Although guaranteed to be portable, users would be overly
burdened by having to convert there graphics to source files (encoded in
their compiler's required format--ASCII, EBCDIC, etc.) using some
arguably amazing character recognition program.

Imagine if, for the sake of true portability, all currently distributed
open source distributions (mainly GZ or BZ2 file) were instead
distributed as character glyphs on a web page--and you were responsible
for converting these graphics to files in your compiler's expected
character encoding.

[snip]
Everything has been invented, all the world's a 32-bit PC running
Windows, and the world has an infinite supply of oil.
And all the world's 32-bit or 64-bit Linux. And food comes from the
supermarket. And water comes from the faucet.

Whether we like it or not, there are people in the real world who think
this way, and we have to deal with them. And if these people don't have
to worry about padding bits in integer types, then it makes our job a lot
easier when managing them. And, thankfully, these people will never work
on C code targeted for the Burroughs B7700.

--
John
Feb 11 '08 #5
John Messenger wrote:
The only sure way to "distribute " portable C source code is via such
mediums as printed books or printed graphics (e.g., what you see on your
monitor when viewing web pages on The Internet, or when viewing posts on
Usenet, etc.). Although guaranteed to be portable, users would be overly
burdened by having to convert there graphics to source files (encoded in
their compiler's required format--ASCII, EBCDIC, etc.) using some
arguably amazing character recognition program.
As long as they only use characters from the basic character set, using
ASCII is just a choice, and there are programs automatically converting
ASCII to EBCDIC. OTOH, the standard doesn't require characters to have
particular glyphs -- that's why trigraphs and <iso646.hexis t, the glyphs
for { or | in some character sets make programs unreadable.

As for which implementations have padding bits, the C99 rationale says:
6.2.6.2 Integer types
Padding bits are user-accessible in an unsigned integer type. For example, suppose a machine
uses a pair of 16-bit shorts (each with its own sign bit) to make up a 32-bit int and the sign
bit of the lower short is ignored when used in this 32-bit int. Then, as a 32-bit signed
int, there is a padding bit (in the middle of the 32 bits) that is ignored in determining the value
20 of the 32-bit signed int. But, if this 32-bit item is treated as a 32-bit unsigned int, then
that padding bit is visible to the user’s program. The C committee was told that there is a
machine that works this way, and that is one reason that padding bits were added to C99.
Footnotes 44 and 45 mention that parity bits might be padding bits. The committee does not
know of any machines with user-accessible parity bits within an integer. Therefore, the
25 committee is not aware of any machines that treat parity bits as padding bits.

Since then, it was required that all-bits-zero be a valid representation
of 0 in any integral type, as many programs expect this (e.g. using
calloc) and there was no known implementation where it wasn't. This rules
out odd parity bits, or at least requires all-bits-zero as an exception.

--
Army1987 (Replace "NOSPAM" with "email")
Feb 11 '08 #6
John Messenger <jo*******@newc omp.netwrote:
>The Burroughs B7700 might have 48-bit words with padding bits, but it
appears to not have a C compiler, let alone a Standard C compiler. Ernie
took these pictures (one of the Burroughs B7700) in 1981, which was about
a decade before the first C Standard came out.
A compiler could have been written after those pictures were taken.
>Based on the lack of responses to my question, I have to conclude that
there are no real-world examples of C compilers that use padding bits, so
we never have to deal with padding bits in the real world.
Don't confuse the "real world" with the small corner you're living in.

Regards,
Ike
Feb 11 '08 #7

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

Similar topics

13
3896
by: Amarendra | last post by:
Folks, This structure padding issue is bothering me now, could not locate a satisfactory answer on clc, so here it goes... I have a structure, given below: typedef struct { int flag; char keys; char padding;
16
6204
by: s.seitz | last post by:
hi gods and programmers! i've got a weird problem with strlen() in C. in a current project, i need to AES_decrypt() some string. By now, i'm using the libssl (openssl) API. To get this AES_decrypt() work, i needed to split the encoded input into pieces of 16 byte. This works as expected.
2
3230
by: manochavishal | last post by:
Hi, In standard i have come across: 6.2.6 Representations of types 6.2.6.1 General 6.When a value is stored in an object of structure or union type, including in a member object, the bytes of the object representation that correspond to any
5
4054
by: Hallvard B Furuseth | last post by:
Does struct assignment copy padding bytes? Some compilers do, but I couldn't find anything in the standard which says they must. What I need is for any padding bytes to contan initialized values before fwrite(), to shut up memory debuggers like Valgrind about writing uninitialized data to the file. Simplified code: static const struct S default_value = ...; struct S s, t;
14
2024
by: Francine.Neary | last post by:
Consider the following situation. I have a large static array s of structs, say of size 500. I also need a smaller array of chars, say of size 100, which has nothing to do with the struct. To conserve memory, I'd like if possible to use (after checking with offsetof and sizeof that there's enough padding to fit a char - usually it will be) space between fields in the structs to store these chars. If the padding is between fields s.a and...
6
4287
by: john | last post by:
Many times I have seen padding bits being mentioned here. What is the purpose of the padding bits?
4
3319
by: Ioannis Vranos | last post by:
Under C95: Is it guaranteed that char, unsigned char, signed char have no padding bits?
3
3867
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
1688
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
9706
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
10578
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
10332
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...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
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...
1
7620
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
5522
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...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.