473,472 Members | 2,153 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Intrinsic Minimums

I've been searching the Standard for info about the minimum
"bits" of the intrinsic types, but haven't been able to
find it. Could anyone please point me to it?

-JKop
Jul 22 '05 #1
15 1657
JKop <NU**@NULL.NULL> wrote in news:j%*****************@news.indigo.ie:
I've been searching the Standard for info about the minimum
"bits" of the intrinsic types, but haven't been able to
find it. Could anyone please point me to it?


It's not defined. Best you've got is that sizeof(char) == 1, and sizeof
(short) <= sizeof(int) <= sizeof(long).

However, that's in bytes, not bits. It is implementation-defined as to how
many bits are in a byte. sizeof(int) is the "natural size suggested by the
architecture of the execution environment'. (Section 3.9)

And I think CHAR_BIT specifies the number of bits in a char... but that
appears to be defined in the C Standard (in <limits.h>)
Jul 22 '05 #2
On Thu, 22 Jul 2004 22:10:35 GMT, Andre Kostur <nn******@kostur.net> wrote:
JKop <NU**@NULL.NULL> wrote in news:j%*****************@news.indigo.ie:
I've been searching the Standard for info about the minimum
"bits" of the intrinsic types, but haven't been able to
find it. Could anyone please point me to it?


It's not defined. Best you've got is that sizeof(char) == 1, and sizeof
(short) <= sizeof(int) <= sizeof(long).

However, that's in bytes, not bits. It is implementation-defined as to
how
many bits are in a byte. sizeof(int) is the "natural size suggested by
the
architecture of the execution environment'. (Section 3.9)

And I think CHAR_BIT specifies the number of bits in a char... but that
appears to be defined in the C Standard (in <limits.h>)


C requires short >= 16 bits, int >= 16 bits, long >= 32 bits. These
minimums are implied by the constraints given on INT_MIN, INT_MAX etc. in
<limits.h>. Presumably C++ inherits this from C.

john
Jul 22 '05 #3
John Harrison posted:

C requires short >= 16 bits, int >= 16 bits, long >= 32 bits. These minimums are implied by the constraints given on INT_MIN, INT_MAX etc. in
<limits.h>. Presumably C++ inherits this from C.

john

I'm writing a prog that'll use Unicode. To represent a
Unicode character, I need a data type that can be set to
65,536 distinct possible values; which in the today's world
of computing equates to 16 bits. wchar_t is the natural
choice, but is there any guarantee in the standard that'll
it'll be 16 bits? If not, then is unsigned short the way to
go?

This might sound a bit odd, but... if an unsigned short
must be atleast 16 bits, then does that *necessarily* mean
that it:

A) Must be able to hold 65,536 distinct values.
B) And be able to store integers in the range 0 -> 65,535 ?

Furthermore, does a signed short int have to be able to
hold a value between:

A) -32,767 -> 32,768

B) -32,768 -> 32,767

I've also heard that some systems are stupid enough (opps!
I mean poorly enough designed) to have two values for zero,
resulting in:

-32,767 -> 32,767
For instance, I don't care if some-one tells me it's 3
bits, just so long as it can hold 65,536 distinct values!
-JKop
Jul 22 '05 #4

I've just realized something:

char >= 8 bits
short int >= 16 bits
int >= 16 bits
long int >= 32 bits

And:

short int >= int >= long int
On WinXP, it's like so:

char : 8 bits
short : 16 bits
int : 32 bits
long : 32 bits
Anyway,

Since there's a minimum, why haven't they just be given definite values!
like:

char : 8 bits
short : 16 bits
int : 32 bits
long : 64 bits

or maybe even names like:

int8
int16
int32
int64

And so then if you want a greater amount of distinct possible values,
there'll be standard library classes. For instance, if you want a 128-Bit
integer, then you're looking for a data type that can store 3e+38 approx.
distinct values. Well... if a 64-Bit integer can store 1e+19 approx values,
then put two together and viola, you've got a 128-Bit number:

class int128
{
private:

int64 a;
int64 b;
//and so on
};

Or while I'm thinking about that, why not be able to specify whatever size
you want, as in:

int8 number_of_sisters;

int16 population_my_town;

int32 population_of_asia;

int64 population_of_earth;

or maybe even:

int40 population_of_earth;
Some people may find that this is a bit ludicrious, but you can do it
already yourself with classes: if you want a 16,384 bit number, then all you
need to do is:

class int16384
{
private:
unsigned char data[2048];

//and so on

};

Or maybe even be able to specify how many distinct possible combinations you
need. So for unicode:

unsigned int<65536> username[15];
This all seems so simple in my head - why can't it just be as so!
-JKop
Jul 22 '05 #5
JKop <NU**@NULL.NULL> wrote in news:IW*****************@news.indigo.ie:

I've just realized something:

char >= 8 bits
short int >= 16 bits
int >= 16 bits
long int >= 32 bits

And:

short int >= int >= long int
On WinXP, it's like so:

char : 8 bits
short : 16 bits
int : 32 bits
long : 32 bits


That's one platform. There are also platforms with 9 bit chars, and 36
bit ints..... (at least if I recall correctly, it was 36 bits...)
Jul 22 '05 #6

JKop wrote:
I'm writing a prog that'll use Unicode. To represent a
Unicode character, I need a data type that can be set to
65,536 distinct possible values; which in the today's world
of computing equates to 16 bits. wchar_t is the natural
choice, but is there any guarantee in the standard that'll
it'll be 16 bits? If not, then is unsigned short the way to
go?


16 bits will always store 65,536 distinct values, regardless of what
day's world the programmer is living in, and regardless of how the
platform interprets those 65,536 values (eg, positive and negative 0).

as far as my reading goes there are no explicit guarantees for the size
of wchar_t. however, wchar_t will be (in essence) an alias for one of
the other integer types. what i am not sure of is whether or not
"integer types" includes any of the char derivatives. if not, then the
underlying type for wchar_t must be either short, int, or long, which
would therefore imply a minimum of 16 bits.

could someone confirm or deny my interpretation here?

now, on another less c++-y note, you have made the classic java
"misunderestimation" of unicode. unicode characters may require up to 32
bits, not 16
(http://www.unicode.org/standard/prin...ncoding_Forms). given
that gem, your *best* bet would appear to be not wchar_t, not short, but
*long*.

of course, you should have no problem extending the iostreams, strings,
etc. for the new character type ^_^. enjoy.

indi

Jul 22 '05 #7
JKop <NU**@NULL.NULL> wrote:

I'm writing a prog that'll use Unicode. To represent a
Unicode character, I need a data type that can be set to
65,536 distinct possible values;
There were more than 90,000 possible Unicode characters last
time I looked (there are probably more now).

If you use a 16-bit type to store this, you have to either:
- Ignore characters whose code is > 65535, or
- Use a multi-byte encoding such as UTF-16, and then all of
your I/O functions will have to be UTF-16 aware.
which in the today's world of computing equates to 16 bits.
A bit of mathematical thought will convince you that you need
at least 16 Binary digITs to represent 2^16 values.
wchar_t is the natural choice, but is there any guarantee
in the standard that'll it'll be 16 bits?
No, in fact it's unlikely to be 16 bit. It's only guaranteed to be
able to support "the largest character in all supported locales",
and locales are implementation-dependent, so it could be 8-bit on
a system with no Unicode support.

On MS windows, some compilers (eg. gcc) have 32-bit wchar_t and
some (eg. Borland, Microsoft) have 16-bit. On all other systems
that I've encountered, it is 32-bit.

This is quite annoying (for people whose language falls in the
over-65535 region especially). One can only hope that MS will
eventually come to their senses, or perhaps that someone will
standardise a system of locales.

If you want to write something that's portable to all Unicode
platforms, you will have to use UTF-16 for your strings,
unfortunately. This means you can't use all the standard library
algorithms on them. Define a type "utf16_t" which is an unsigned short.

The only other alternative is to use wchar_t and decode UTF-16
to plain wchar_t (ignoring any characters outside the range of
your wchar_t) whenever you receive a wchar_t string encoded as
UTF-16. (and don't write code that's meant to be used by Chinese).
This might sound a bit odd, but... if an unsigned short
must be atleast 16 bits, then does that *necessarily* mean
that it:

A) Must be able to hold 65,536 distinct values.
B) And be able to store integers in the range 0 -> 65,535 ?
Yes
Furthermore, does a signed short int have to be able to
hold a value between:

A) -32,767 -> 32,768

B) -32,768 -> 32,767
No
I've also heard that some systems are stupid enough (opps!
I mean poorly enough designed) to have two values for zero,
resulting in:

-32,767 -> 32,767


Yes (these are all archaic though, from a practical point of
view you can assume 2's complement, ie. -32768 to 32767).
FWIW the 3 supported systems are (for x > 0):
2's complement: -x == ~x + 1
1's complement: -x == ~x
sign-magnitude: -x = x & (the sign bit)
Jul 22 '05 #8
C requires short >= 16 bits, int >= 16 bits, long >= 32 bits. These
minimums are implied by the constraints given on INT_MIN, INT_MAX etc. in
<limits.h>. Presumably C++ inherits this from C.


Yes, that's correct.
At the end of section 18.2.2, there is a specific reference to ISO C
subclause
5.2.4.2.1. So this section is included by reference. This section gives
definition of CHAR_BIT, UCHAR_MAX etc.

-Sharad


Jul 22 '05 #9
>
This might sound a bit odd, but... if an unsigned short
must be atleast 16 bits, then does that *necessarily* mean
that it:

A) Must be able to hold 65,536 distinct values.
B) And be able to store integers in the range 0 -> 65,535 ?

Yes, USHRT_MIN must be at least 65535, and all unsigned types must obey
the laws of modulo 2-to-the-power-N arithmetic where N is the number of
bits. I think that implies that the minimum value is 0, and that all
values between 0 and 2 to-the-power-N - 1 must be represented.
Furthermore, does a signed short int have to be able to
hold a value between:

A) -32,767 -> 32,768

B) -32,768 -> 32,767

I've also heard that some systems are stupid enough (opps!
I mean poorly enough designed) to have two values for zero,
resulting in:

-32,767 -> 32,767

That's correct. I seriously doubt you would meet such a system in practise
(except in a museum).

For instance, I don't care if some-one tells me it's 3
bits, just so long as it can hold 65,536 distinct values!
-JKop


john
Jul 22 '05 #10
Mark A. Gibbs posted:
of course, you should have no problem extending the iostreams, strings, etc. for the new character type ^_^. enjoy.


You're absolutley correct

basic_string<unsigned long> stringie;
-JKop
Jul 22 '05 #11
Old Wolf posted:
from a practical point of
view you can assume 2's complement, ie. -32768 to 32767).
FWIW the 3 supported systems are (for x > 0):
2's complement: -x == ~x + 1
1's complement: -x == ~x
sign-magnitude: -x = x & (the sign bit)


sS wouldn't that be -32,767 -> 32,768?

I assume that 1's compliment is the one that has both positive and negative
0.
As for the sign-magnitude thingie, that's interesting!

unsigned short blah = 65535;

signed short slah = blah;

slah == -32767 ? ?
-JKop
Jul 22 '05 #12

"JKop" <NU**@NULL.NULL> wrote in message
news:ma*****************@news.indigo.ie...
Mark A. Gibbs posted:
of course, you should have no problem extending the

iostreams, strings,
etc. for the new character type ^_^. enjoy.


You're absolutley correct

basic_string<unsigned long> stringie;


I think you'll also need a char_traits class.

basic_string<unsigned long, ul_char_traits> stringie;

john
Jul 22 '05 #13
JKop wrote:
John Harrison posted:

C requires short >= 16 bits, int >= 16 bits, long >= 32 bits. These
minimums are implied by the constraints given on INT_MIN,

INT_MAX etc.
in
<limits.h>. Presumably C++ inherits this from C.

john

I'm writing a prog that'll use Unicode. To represent a
Unicode character, I need a data type that can be set to
65,536 distinct possible values;


No, you need more for full unicode support.
which in the today's world of computing equates to 16 bits. wchar_t is
the natural choice, but is there any guarantee in the standard that'll
it'll be 16 bits?
It doesn't need to be exactly 16 bit. It can be more. In g++, it's 32
bits.
If not, then is unsigned short the way to go?

This might sound a bit odd, but... if an unsigned short
must be atleast 16 bits, then does that *necessarily* mean
that it:

A) Must be able to hold 65,536 distinct values.
B) And be able to store integers in the range 0 -> 65,535 ?
It's actually rather the other way round. It must explicitly be able to
hold at least the range from 0 to 65535, which implies a minimum of 16
bits.
Furthermore, does a signed short int have to be able to
hold a value between:

A) -32,767 -> 32,768

B) -32,768 -> 32,767
Neither.
I've also heard that some systems are stupid enough (opps!
I mean poorly enough designed) to have two values for zero,
resulting in:

-32,767 -> 32,767


That's the minimum range that a signed short int must support.

Jul 22 '05 #14
JKop wrote:

I've just realized something:

char >= 8 bits
short int >= 16 bits
int >= 16 bits
long int >= 32 bits
Yes.
And:

short int >= int >= long int
Uhm, no. But I guess it's just a typo :)
On WinXP, it's like so:

char : 8 bits
short : 16 bits
int : 32 bits
long : 32 bits
Anyway,

Since there's a minimum, why haven't they just be given definite
values! like:

char : 8 bits
short : 16 bits
int : 32 bits
long : 64 bits
Because there are other platforms for which other sizes may fit better.
There are even systems that only support data types with a multple of
24bit as size. C++ can still be implemented on those, because the size
requirements in the standard don't have fixed values. Also, int is
supposed (though not required) to be the machine's native type that is
the fastest one. On 64 bit platforms, it often isn't though.
or maybe even names like:

int8
int16
int32
int64
C99 has something like this in the header <stdint.h>. It further defines
smallest and fastest integers with a specific minimum size, like:

int_fast16_t
int_least32_t

This is a good thing, because an exact size is only needed rarely. Most
often, you don't care for the exact size as long as it's the fastest
resp. smallest type that provides at least a certain range.
And so then if you want a greater amount of distinct possible values,
there'll be standard library classes. For instance, if you want a
128-Bit integer, then you're looking for a data type that can store
3e+38 approx. distinct values. Well... if a 64-Bit integer can store
1e+19 approx values, then put two together and viola, you've got a
128-Bit number:

class int128
{
private:

int64 a;
int64 b;
//and so on
};

Or while I'm thinking about that, why not be able to specify whatever
size you want, as in:

int8 number_of_sisters;

int16 population_my_town;

int32 population_of_asia;

int64 population_of_earth;

or maybe even:

int40 population_of_earth;
Some people may find that this is a bit ludicrious, but you can do it
already yourself with classes: if you want a 16,384 bit number, then
all you need to do is:

class int16384
{
private:
unsigned char data[2048];

//and so on

};

Or maybe even be able to specify how many distinct possible
combinations you need. So for unicode:

unsigned int<65536> username[15];
This all seems so simple in my head - why can't it just be as so!


It isn't as simple as you might think. If it were, you could just start
writing a proof-of-concept implementation. :-)
Jul 22 '05 #15
ol*****@inspire.net.nz (Old Wolf) wrote in message news:<84**************************@posting.google. com>...
JKop <NU**@NULL.NULL> wrote:
On MS windows, some compilers (eg. gcc) have 32-bit wchar_t and
some (eg. Borland, Microsoft) have 16-bit. On all other systems
that I've encountered, it is 32-bit.

This is quite annoying (for people whose language falls in the
over-65535 region especially). One can only hope that MS will
eventually come to their senses, or perhaps that someone will
standardise a system of locales.


It is hardly annoying for these people, because they died long before
computers were invented. Non-BMP region contains mostly symbols for
dead languages.
Jul 22 '05 #16

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

Similar topics

1
by: Glenn Venzke | last post by:
I'm trying to write/compile a class that (1) accesses all the intrinsic ASP.NET objects (2) Uses Server.Transfer to redirect a user back to a log in page if a session has expired. I've gotten...
5
by: Jeremy Cowles | last post by:
I have been reading a book that focuses on understanding the intrinsic types of C++ in depth. The author's mentality is this: "Understand the intrinsic types, then learn the std types as needed...
3
by: George M. Garner Jr. | last post by:
Is there an intrinsic to wrap the bswap x86 instruction. I have written a function to do this with inline assembler but I am wondering if an intrinsic wouldn't be a better solution. Regards, ...
13
by: Alek Davis | last post by:
Hi, Is it possible to access intrinsic ASP objects, such as Request, from a .NET class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can this library retrieve the request info...
7
by: A Traveler | last post by:
Hello all, i was just curious if anyone whos been playing with VS2005 could tell me... In javascript (and java??) you can alter the prototypes for an object in your project. I dont remember...
0
by: albean | last post by:
I I have a number of VB COM components used in ASP pages that access some intrinsic ASP objects. Basically we would get the context from COMSVCSLib and from there get the ASP Request and Response...
2
by: jason | last post by:
hello everyone, i have had a suppot ticket open with microsoft for some time to investigate a memory leak issue we are experiencing on our production web servers. the web servers host both ASP...
8
by: Thelma Lubkin | last post by:
I have finally nagged more work out of the non-profit organization that I'm trying to do volunteer work for. The following code begins a tiny form that is part of the project that I'll be...
2
by: Bryan Parkoff | last post by:
Do you know where I can find a good book how to write intrinsic function? Intrinsic function is useful to use MMX or SSE or any SIMD instruction of x86 and other machines for best portability. It...
0
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...
0
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,...
0
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...
1
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
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.