473,883 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Natural size: int


On modern 32-Bit PC's, the following setup is common:

char: 8-Bit
short: 16-Bit
int: 32-Bit
long: 32-Bit

"char" is commonly used to store text characters.
"short" is commonly used to store large arrays of numbers, or perhaps wide
text characters (via wchar_t).
"int" is commonly used to store an integer.
"long" is commonly used to store an integer greater than 65535.

Now that 64-Bit machines are coming in, how should the integer types be
distributed? It makes sense that "int" should be 64-Bit... but what should
be done with "char" and "short"? Would the following be a plausible setup?

char: 8-Bit
short: 16-Bit
int: 64-Bit
long: 64-Bit

Or perhaps should "short" be 32-Bit? Or should "char" become 16-Bit (i.e.
16 == CHAR_BIT).

Another semi-related question:

If we have a variable which shall store the quantity of elements in an
array, then should we use "size_t"? On a system where "size_t" maps to
"long unsigned" rather than "int unsigned", it would seem to be inefficient
most of the time. "int unsigned" guarantees us at least 65535 array
elements -- what percentage of the time do we have an array any bigger than
that? 2% maybe? Therefore would it not make sense to use unsigned rather
than size_t to store array lengths (or the positive result of subtracting
pointers)?

--

Frederick Gotham
Aug 8 '06
78 3914
Ian Collins wrote:
jacob navia wrote:
>>For windows systems, Microsoft decided that with 64 bit machines it
will be
char 8, short 16, int 32, long 32, __int64 64

For unix systems, gcc decided that
char 8, short 16, int 32, long 64, long long 64

gcc decided? I don't think so.

LP64 is by far the most common model on UNIX and UNIX like systems and
the main reason is probably pragmatic - it's the most straightforward
model to port 32 bit applications to.
Microsoft disagrees... :-)

I am not saying that gcc's decision is bad, I am just stating this as
a fact without any value judgement. Gcc is by far the most widely
used compiler under Unix, and they decided LP64, what probably is a good
decision for them.

Microsoft decided otherwise because they have another code base.

And lcc-win32 did not decide anything. Under windows I compile
for long 32 bits, under Unix I compiler for long 64 bits.

I have to follow the lead compiler in each system. By the way, the
lead compiler in an operating system is the compiler that compiled
the Operating System: MSVC under windows, gcc under linux, etc.

Aug 8 '06 #21
Al Balmer <al******@att.n etwrites:
On Tue, 08 Aug 2006 19:42:19 +0200, jacob navia
<ja***@jacob.re mcomp.frwrote:
>>For unix systems, gcc decided that
char 8, short 16, int 32, long 64, long long 64

For *some* Unix systems, perhaps.

On HP-UX, a long is still 32 bits.
gcc has 32-bit longs on some systems, 64-bit longs on others. For the
most part, the division is between "32-bit systems" and "64-bit
systems", though neither phrase is particularly meaningful. I know
that some versions of HP-UX are 32-bit systems, so it wouldn't
surprise me to see 32-bit longs. If there are 64-bit versions of
HP-UX, I'd expect gcc to have 64-bit long on that system, though I
wouldn't depend on it.

I *think* that gcc typically has sizeof(long) == sizeof(void*). In
fact, all the systems I currently use, perhaps even all the systems
I've ever used, have sizeof(long)==s izeof(void*) (either 32 or 64
bits), though of course there's no requirement for them to be the same
size.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 8 '06 #22
Keith Thompson wrote:
Al Balmer <al******@att.n etwrites:
>>On Tue, 08 Aug 2006 19:42:19 +0200, jacob navia
<ja***@jacob. remcomp.frwrote :
>>>For unix systems, gcc decided that
char 8, short 16, int 32, long 64, long long 64

For *some* Unix systems, perhaps.

On HP-UX, a long is still 32 bits.


gcc has 32-bit longs on some systems, 64-bit longs on others. For the
most part, the division is between "32-bit systems" and "64-bit
systems", though neither phrase is particularly meaningful. I know
that some versions of HP-UX are 32-bit systems, so it wouldn't
surprise me to see 32-bit longs. If there are 64-bit versions of
HP-UX, I'd expect gcc to have 64-bit long on that system, though I
wouldn't depend on it.

I *think* that gcc typically has sizeof(long) == sizeof(void*). In
fact, all the systems I currently use, perhaps even all the systems
I've ever used, have sizeof(long)==s izeof(void*) (either 32 or 64
bits), though of course there's no requirement for them to be the same
size.
That's a VERY wise decision.

Microsoft's decision of making sizeof(long) < sizeof(void *)
meant a LOT OF WORK at a customer's site recently. It was a basic
assumption of thir code.

Aug 8 '06 #23
jacob navia wrote:
Ian Collins wrote:
>jacob navia wrote:
>>For windows systems, Microsoft decided that with 64 bit machines it
will be
char 8, short 16, int 32, long 32, __int64 64

For unix systems, gcc decided that
char 8, short 16, int 32, long 64, long long 64

gcc decided? I don't think so.

LP64 is by far the most common model on UNIX and UNIX like systems and
the main reason is probably pragmatic - it's the most straightforward
model to port 32 bit applications to.

Microsoft disagrees... :-)
My comment was based on my experience with Sparc, I'm sure LP64 was
adopted as the 64 bit ABI (mainly to support mixed 32 and 64
applications IIRC) before gcc had a 64 bit Sparc port.

A bit OT, but can you mix 32 and 64 bit applications on 64 bit windows?
>
I have to follow the lead compiler in each system. By the way, the
lead compiler in an operating system is the compiler that compiled
the Operating System: MSVC under windows, gcc under linux, etc.
You have to, if you want to link with the system libraries!

--
Ian Collins.
Aug 8 '06 #24
On Wed, 09 Aug 2006 00:45:03 +0200, jacob navia
<ja***@jacob.re mcomp.frwrote:
>Al Balmer wrote:
>On Tue, 08 Aug 2006 19:42:19 +0200, jacob navia
<ja***@jacob.r emcomp.frwrote:

>>>For unix systems, gcc decided that
char 8, short 16, int 32, long 64, long long 64


For *some* Unix systems, perhaps.

On HP-UX, a long is still 32 bits.
Interesting. ..

What does gcc do in those systems?

It follows HP or remains compatible with itself?
It follows HP, naturally. It even uses HP libraries. On HP-UX
Integrity, it's a decent compiler, but can't yet produce optimized
code for the Itanium processor.

I find the idea of a compiler remaining "compatible with itself" to be
rather odd.

--
Al Balmer
Sun City, AZ
Aug 8 '06 #25
Ian Collins wrote:
jacob navia wrote:
>>Ian Collins wrote:

>>>jacob navia wrote:
For windows systems, Microsoft decided that with 64 bit machines it
will be
char 8, short 16, int 32, long 32, __int64 64

For unix systems, gcc decided that
char 8, short 16, int 32, long 64, long long 64
gcc decided? I don't think so.

LP64 is by far the most common model on UNIX and UNIX like systems and
the main reason is probably pragmatic - it's the most straightforward
model to port 32 bit applications to.

Microsoft disagrees... :-)

My comment was based on my experience with Sparc, I'm sure LP64 was
adopted as the 64 bit ABI (mainly to support mixed 32 and 64
applications IIRC) before gcc had a 64 bit Sparc port.

A bit OT, but can you mix 32 and 64 bit applications on 64 bit windows?
No. You can't load a 32 bit DLL (shared object) from a 64 bit
process. Of course you can use system() to call a 32 bit
application but that is another process that runs in the 32 bit
emulation layer.
>
>>I have to follow the lead compiler in each system. By the way, the
lead compiler in an operating system is the compiler that compiled
the Operating System: MSVC under windows, gcc under linux, etc.

You have to, if you want to link with the system libraries!
Yes, that's the reason.
Aug 8 '06 #26
jacob navia writes:
For unix systems, gcc decided that
char 8, short 16, int 32, long 64, long long 64
gcc decided to do whatever the system was already doing to the best of
its ability, so that gcc-compiled code could be used with existing
libraries (like the C library:-) It contains a lot of code to figure
that out.

If it didn't, nobody would have used it. Remember, gcc is older than
Linux & co. When the GNU project was started, Unixes were full of
proprietary closed-source libraries - and there are still plenty of them
around, on systems where gcc is in use.

--
Hallvard
Aug 9 '06 #27
The funny thing is this issue was partly solved in 1958, 1964, and in
1971.

In 1958 Grace Hopper and Co. designed COBOL so you could actually
declare variables and their allowed range of values! IIRC something
like:

001 DECLARE MYPAY PACKED-DECIMAL PICTURE "999999999999V9 99"
001 DECLARE MYPAY USAGE IS COMPUTATIONAL-/1/2/3

Miracle! A variable with predictable and reliable bounds! Zounds!
But this still isnt quite the ticket, you can only specify decimal
numbers to arbitrary and dependable precision, floating-point numbers
are still a hodge-podge.

Then in 1964 PL/I (may it rest in peace) tried to combine COBOL and
Fortran and Algol, with mixed results. But they did extend
declarations to make variable declarations a bit better, so you could
specify, separately, decimal or binary math, and the number of decimal
places before and after the decimal point:

dcl J fixed binary (7);
dcl K fixed bin (8) unsigned;
dcl L fixed bin (15);
dcl M fixed bin;
dcl N fixed bin (31);
dcl O fixed bin (31,16);
dcl S fixed dec (7,2);

Still not quite the ticket.
Then in 1971 Pascal went in a slightly different direction, but not far
enough, by letting you specify explicit variable bounds, but only for
integer and scalar (enum) types:

var Year: 1900..3000;

------

What the typical user REALLY needs, and may not be doable in any simple
or portable way, is a wide choice of what one wants:

Case (1): I need an integer that can represent the part numbers in a
1996 Yugo, well known to range from 0 to 12754. Pascal leads the way
here: var PartNumber: 0..12754.

Case (2): I need a real that can represent the age of the universe, in
Planck units, about 3.4E-42 to 12.E84. The accuracy of measurement is
only plus or minus 20 percent, so two significant digits is plenty.
PL/I is the only language I know of that can adequately declare this:
DECLARE AGE FLOAT BINARY (2,85). Which hopefully the compiler will map
to whatever floating-point format can handle that exponent.

case (3): I need an integer that can do exact math with decimal prices
from 0.01 to 999,999,999,99. COBOL and PL/I can do this.

case (4): I need a 32-bit integer. Pascal and PL/I are the only
languages that can do this: var I32: -$7FFFFFFF..$7FF FFFFF; PL/I:
DECLARE I32 FIXED BINARY (32).

case (5): I need whatever integer format is fastest on this CPU and
is at least 32 bits wide. Don't know of any language that has this
capability.

------------------------

<soap>
I think it's high time a language has the ability to do the very basic
and simple things programmers need to write portable software: the
ability to specify, unambiguously, what range of values they need to
represent, preferably in decimal, binary, floating, fixed, and even
arbitrary bignum formats. Not to mention hardware-dependent perhaps
bit widths. There's no need for the compiler to be able to actually
*do* any arbitrarily difficult arithmetic, but at least give the
programmer the ability to ASK and if the compiler is capable, and get
DEPENDABLE math. I don't think this is asking too much.

The biness of C having wink-wink recognized defacto binary integer
widths is IMHO just way below contempt. The way was shown many
different times since 1958, why can't we get something usable, portable
and reasonable now quite a ways into the 21st century?
</soap>

Aug 9 '06 #28
"Ancient_Hacker " <gr**@comcast.n etwrites:
>
<soap>
I think it's high time a language has the ability to do the very basic
and simple things programmers need to write portable software: the
ability to specify, unambiguously, what range of values they need to
represent, preferably in decimal, binary, floating, fixed, and even
arbitrary bignum formats. Not to mention hardware-dependent perhaps
bit widths. There's no need for the compiler to be able to actually
*do* any arbitrarily difficult arithmetic, but at least give the
programmer the ability to ASK and if the compiler is capable, and get
DEPENDABLE math. I don't think this is asking too much.
It is if you want the system to perform.

But than ADA does all that you want and more.

And its not usually the compiler that does any arithmetic : its normally
runtime bounds checks. Can be very time consuming. And one reason why C
doesnt do it. C isnt about things like that.
Aug 9 '06 #29
"Ancient_Hacker " <gr**@comcast.n etwrote:
The biness of C having wink-wink recognized defacto binary integer
widths is IMHO just way below contempt. The way was shown many
different times since 1958, why can't we get something usable, portable
and reasonable now quite a ways into the 21st century?
Darling, if you want Ada, you know where to find her.

Richard
Aug 9 '06 #30

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

Similar topics

0
1329
by: C. Barnes | last post by:
Summary: Sorts strings in a way that seems natural to humans. If the strings contain integers, then the integers are ordered numerically. For example, sorts into the order . Code:
3
1750
by: Derek Basch | last post by:
Hello All, I need to sort a list using an unnatural sequence. I have a list like so: foo = print foo.sort()
1
2429
by: Connelly Barnes | last post by:
Summary: Sorts strings in a way that seems natural to humans. If the strings contain integers, then the integers are ordered numerically. For example, sorts into the order . Code: #---------------------------------------------------------
4
2198
by: Andrew E | last post by:
Hi all I've written a python program that adds orders into our order routing simulation system. It works well, and has a syntax along these lines: ./neworder --instrument NOKIA --size 23 --price MARKET --repeats 20 etc However, I'd like to add a mode that will handle, say:
7
1883
by: tommaso.gastaldi | last post by:
This is a curious question. I'd like to know your opinion. I am attaching a drawing resize to a mouse wheel event. Frankly, to me was most natural that, if I mouse wheel UP, the shape gets bigger, while it gets smaller when mouse wheel DOWN. I just noticed that Photoshop does the opposite. Any though about the most natural way (or perhaps are both "natural") ?
1
1766
by: Hendri Adriaens | last post by:
Hi, I have an onmouseover script that displays a div with some comment. There are several links getting this onmouseover functionality, all with their own comment text. Now I want the div to have a max width, but if the natural width is smaller than the max width, it should get the natural width. commentObj is the div and commentObj.offsetWidth returns the natural width, as long as we didn't set it to anything else (it seems). As soon as...
1
2639
by: Steven Bird | last post by:
NLTK — the Natural Language Toolkit — is a suite of open source Python modules, data sets and tutorials supporting research and development in natural language processing. It comes with 50k lines of code, 300Mb of datasets, and a 360 page book which teaches both Python and Natural Language Processing. NLTK has been adopted in at least 40 university courses. NLTK is hosted on sourceforge, and is ranked in the top 200 projects. ...
3
4325
by: anon538 | last post by:
I am creating an application that has to check for natural numbers. By natural numbers, I mean positive whole numbers. //natural needs to equal 1,2,3, etc. if(minutes % 60 == natural) { minuteField.value = minutes; } How can I can I do this? Thanks.
10
8085
by: Ben | last post by:
Hi at all I am looking for the natural size of an image I found this function : while ((imgHeight = image.getHeight(this)) == -1 ) { // loop until image loaded
0
9932
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
9777
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
11109
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
9558
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
7959
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
5782
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
5980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4602
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
4200
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.