64 bit

G

Guest

C++ has no specify how many bytes is "int"

Until now, in most of 32 bit processors, "int" has 4 bytes
is it possible with new 64 bit processors (& compilers) "int" takes 8 bytes?

thanks
 
J

John Harrison

C++ has no specify how many bytes is "int"

Until now, in most of 32 bit processors, "int" has 4 bytes
is it possible with new 64 bit processors (& compilers) "int" takes 8 bytes?

thanks

Yes it is.

There's no completely adequate solution to this problem in C++. I believe
this is addressed by the C99 standard, ask on if you are
interested in this. Presumably one day the C99 standards will be applied to
C++ as well.

john
 
K

Kevin Goodsell

C++ has no specify how many bytes is "int"

Until now, in most of 32 bit processors, "int" has 4 bytes
is it possible with new 64 bit processors (& compilers) "int" takes 8 bytes?

thanks

Basically the rules about the size of int are: It must be at least 16
bits long, able to represent values from -32767 to 32767 (which implies
the "at least 16 bits" rule), and there's a suggestion that it reflect
the "natural word size of the target machine" or something like that.
Also, it may not be longer than long or shorter than short.

Note that int can be as little as 1 byte (without violating the rules
above), meaning sizeof(int) == 1. "bytes" in C++ do not need to be 8
bits long. A byte may be 32 bits long, for example (and I believe there
are implementations where this is the case). On such an implementation
you may have sizeof(char) == sizeof(short) == sizeof(int) ==
sizeof(long) == 1.

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,137
Messages
2,570,802
Members
47,348
Latest member
Mikientp

Latest Threads

Top