473,788 Members | 2,837 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Integer sizes

The most common sizes of integer types seem to be:

8 bits - signed char
16 bits - short
16 or 32 bits - int
32 or 64 bits - long

Question #1:

Does anyone know how common sizes other than these are ? I know that the
standard says that number of bits in a "byte" (char) is >= 8, but I have not
come across values other than these yet ...

Question #2:

Is anyone aware of a package that has some portable definitions of things
like Int8, Int16 and Int32 (assuming they are possible for the platform) ?
If not, I think you could do this using the definitions in <limits.h>
(<climits> ?). I am aware that the preprocessor doesn't understand the
sizeof operator, so you can't do it that way.

Thanks,

David F
Jul 22 '05
14 13034
> >> I work with a C compiler for which, by default, int is 8 bits.

IIRC according to the standard an int should be at least 16 bits. It seems
that your C compiler isn't very standard compliant.
The compiler is compliant, I believe, perhaps because it allows you
to change the meaning of int to 16 bits via a switch.


In that case it is only compliant when you use that switch.
It is a compiler
for PIC microcontroller s, which have 8-bit registers and instructions
only.
That explains something, the PIC processor family has a kinda weird
instruction set. OTOH the cc65 compiler for the 6502 processor (from the
good old days: a true 8-bit processor with no support for 16-bit operations
other than having a carry flag) the int size is 16-bit. But because 16-bit
operations are slow on this processor the compiler documentation recommends
against using int's and recommends use char's instead whenever you can.
I guess most people don't aim to port PIC programs to Posix or
WinXP .. :-)
I guess the PIC compiler doesn't come with a windowing library either :-)
I some cases the target platform is so different from any other platform
that cross-platform compatibility is non-issue anyway.
Personally, I HATE all this business of int, long, long long, double,
double double, and all this incomprehensibl e crap. *And Non-Portable
Crap, I might add*. Most compilers come with headers, I believe,
where they define numeric types more inteligently, like


Yes, it is pain when writing cross-platform code. Unfortunately any
constructs a compiler may have to explicitly specify the size are
non-standard. I would welcome standardization in this area.


I'd like to see something really drastic done about this whole issue,
maybe something like announcing that keywords such as int, long,
short, etc. are to be deprecated and eventually removed from the
language, to encourage change.


Don't hold you breath, I don't see that happen in my life time (I do plan
to be around for another couple of decades)
But for this to happen, something else
must come first: Units.
There's a company that came up with a template library called SIUnits,
which allows you to define classes representing distances, areas,
volumes, weights, densities, pressures, electron densities,
currencies, temperatures, and what not; expressed in various systems
of units. Their system is a bit too complex for my taste, including
physics models for six areas of application, including scientific,
relativistic and non-relativistic...

I'd be happy with a system that just makes sure you don't add
millimiters to inches and divide by celsius to get dollars, if you
know what I mean.


I understand what you mean. You can do that easilly in C++; just make a
classes for millimiters, inches, celcius and dollars and bit of operator
overloading magic. Having done that, if you add millimeters to inches, you
can either choose to get a compile error, or apply the correct conversion
automagically.

--
Peter van Merkerk
peter.van.merke rk(at)dse.nl
Jul 22 '05 #11
On Thu, 04 Dec 2003 01:23:36 -0500, Dan W. <da**@raytron-controls.com>
wrote in comp.lang.c++:

[snip]
I work with a C compiler for which, by default, int is 8 bits.
The people who produced it claim that it is a C compiler, but they are
lying, it is not. It is a different language that imitates part of C.
Personally, I HATE all this business of int, long, long long, double,
double double, and all this incomprehensibl e crap. *And Non-Portable
Crap, I might add*. Most compilers come with headers, I believe,
where they define numeric types more inteligently, like

__INT08
__INT16
...
__UINT08
__UINT16


Yes, and other compilers come with libraries that define them as U8,
S16, and so on, or BYTE and UWORD, and so on, and dozens of similar,
but not identical, varieties.

That's the whole point of using the C standard <stdint.h>. They are
probably not the prettiest names for exact width types ever invented,
but they are standard now in C and will be standard in C++.

So you won't have to edit the compiler-specific type names to a
different set of compiler-specific type names each time you port your
code to a different compiler or processor.

Any set of standard names that clearly express what they define is
better than dozens of non-standard names made up independently by each
compiler and library writer.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jul 22 '05 #12
On Thu, 04 Dec 2003 16:10:07 +1100, David Fisher wrote:
The most common sizes of integer types seem to be:

8 bits - signed char
16 bits - short
16 or 32 bits - int
32 or 64 bits - long

Question #1:

Does anyone know how common sizes other than these are ? I know that the
standard says that number of bits in a "byte" (char) is >= 8, but I have not
come across values other than these yet ...


Apparently a lot of embedded systems use char, short, int and long of 32
bits. Some older machines (PDP?) used 9 bit chars (and 36 bit ints, IIRC.)

Simplest solution: use the size guaranteed to have _at least_ as many bits
as you need, but don't assume it'll _only_ have that many.
Jul 22 '05 #13
On Thu, 4 Dec 2003 14:51:46 +0100, "Peter van Merkerk"
<me*****@deadsp am.com> wrote:

I understand what you mean. You can do that easilly in C++; just make a
classes for millimiters, inches, celcius and dollars and bit of operator
overloading magic. Having done that, if you add millimeters to inches, you
can either choose to get a compile error, or apply the correct conversion
automagicall y.


Nothing is as easy as first sounds in this business; luckily some
people at boost are taking a crack at it:

http://lists.boost.org/MailArchives/boost/msg29353.php

Here's a link to some attempt at a formal specification:

http://www.servocomm.freeserve.co.uk...ical_quantity/

Cheers!
Jul 22 '05 #14
"David Fisher" <no****@nospam. nospam.nospam> wrote in message news:<3n******* ***********@nas al.pacific.net. au>...
The most common sizes of integer types seem to be:

8 bits - signed char
16 bits - short
16 or 32 bits - int
32 or 64 bits - long

Question #1:

Does anyone know how common sizes other than these are ? I know that the
standard says that number of bits in a "byte" (char) is >= 8, but I have not
come across values other than these yet ...


Well, my current CPU has char=16 bits, short=16 bits, int=16 bits,
long=32 bits (thank goodness).

As for why I'd want to use octets - well, a factor of 2 expansion in
ROM size ain't nice, and also would make the peripherals (sound,
graphics, etc.) behave funny. So the data has to be preprocessed to
join it up into 16 bit chunks.
Jul 22 '05 #15

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

Similar topics

3
2521
by: Simon G Best | last post by:
Hello! The C++ standard library provides facilities for finding out the sizes (and other such stuff) of numeric types (::std::numeric_limits<>, for example). What I would like to do is to select a type on the basis of its traits. More specifically, I would like to select an unsigned integer type on the basis of the number of bits I need it to have. (This is because there are particularly efficient ways of implementing the Advanced
30
2382
by: JKop | last post by:
When you want to store an integer in C++, you use an integral type, eg. int main() { unsigned char amount_legs_dog = 4; } In writing portable C++ code, there should be only two factors that influence which integral type you choose:
28
2511
by: Timothy Madden | last post by:
Hello I've read here that only C language has a standard 64bit integer. Can you please tell me what are the reasons for this ? What is special about C language ? Can you please show me some references to this integer type ? When was it introduced ? Thank you
20
9176
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg., int_fast32_t 4) integer capable of holding a pointer, intptr_t 5) widest integer in the implementation, intmax_t Is there a valid motivation for having both int_least and int_fast?
61
3392
by: John Baker | last post by:
When declaring an integer, you can specify the size by using int16, int32, or int64, with plain integer being int32. Is integer the accepted default in the programming community? If so, is there a way to remove the ones with size predefined from the autolisting of types when I am declaring something? -- To Email Me, ROT13 My Shown Email Address
21
4137
by: Frederick Gotham | last post by:
I set about trying to find a portable way to set the value of UCHAR_MAX. At first, I thought the following would work: #define UCHAR_MAX ~( (unsigned char)0 ) However, it didn't work for me. Could someone please explain to me what's going on? I would have thought that the following happens: (1) The literal, 0, whose type is int, gets converted to an unsigned char.
40
2816
by: Robert Seacord | last post by:
The CERT/CC has released a beta version of a secure integer library for the C Programming Language. The library is available for download from the CERT/CC Secure Coding Initiative web page at: http://www.cert.org/secure-coding/ The purpose of this library is to provide a collection of utility functions that can assist software developers in writing C programs that are free from common integer problems such as integer overflow, integer...
159
6339
by: Bob Timpkinson | last post by:
Hi, I have a 32-bit machine... Is there anyway I can get gcc to use the following integer sizes? char: 8 bits short: 16 bits int: 32 bits long: 64 bits long long: 128 bits
0
9656
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
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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...
1
10112
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
9969
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
8993
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
7518
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
6750
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();...
0
5399
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...

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.