what will be the size of data types(long, int, char, short) on a 64-
bit architecture?
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
> what will be the size of data types(long, int, char, short) on a 64-
> bit architecture?
Whatever the implementation wants them to be, which will be different
for different implementations of C.
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
> what will be the size of data types(long, int, char, short) on a 64-
> bit architecture?
Whatever the implementor decides to make them --- within the limitations set by the standard, hopefully.
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
> what will be the size of data types(long, int, char, short) on a 64-
> bit architecture?
It really depends on what the implementation decides.
It if very likely that char will be 8, and short 16 bits.
int, while it legally could be 16 bits is actually probably 32 or 64 bits. The 32 bit choice has the advantages that it hides many porting problems from programmers on 32 bit machines just assuming int is 32 bits. It also provides a "standard" type for 32 bits.
int could also be 64 bits, to meet the intent of the standard for int to be the "natural" size of the processor, but this then says that a 32 bit type must be an "extended integer type" which is a concept many programmers aren't comfortable with.
long is probably 64 bits, but if int is 32 bits, it might also be 32 bits for backwards compatibility. If int is 64 bits, there may be some reasoning that long should then be 128 bits, for people used to long being bigger than int, but most of that has been stamped out by the prevalence of 32 bit machines with both 32 bit int and long.
long long is probably a 128 bit type (unless long is, then it is likely 256 bits).
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
> what will be the size of data types(long, int, char, short) on a 64-
> bit architecture?
Whatever the compiler chooses it to be.
For GNU, sizeof(char) = 1 (as always and mandated by the standard),
sizeof(short) = 2, sizeof(int) = 4, sizeof(long) = 8, sizeof(long long) = 8.
For VS, sizeof(char) = 1, sizeof(short) = 2, sizeof(int) = 4, sizeof(long) = 4, sizeof(long long) = 8.
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Chiru Reddy <chiru.0123456...@gmail.com> writes:
> what will be the size of data types(long, int, char, short) on a 64-
> bit architecture?
It depends. Here is a partial list for FreeBSD/amd64, which is fairly
typical:
byte order 1234
char is signed
type size alignment
--------------------------------------
char 8 8
short 16 16
int 32 32
long 64 64
long long 64 64
intmax_t 64 64
float 32 32
double 64 64
long double 128 128
size_t 64 64
ptrdiff_t 64 64
time_t 64 64
void_ptr 64 64
func_ptr 64 64
wchar_t 32 32
sig_atomic_t 64 64
This model is commonly known as I32LP64. Linux/x86_64 is similar
except that sig_atomic_t is 32 bits wide. I haven't tested any other
operating systems.
You can get the source code for the program that generated this list
from <URL:http://svn.freebsd.org/base/user/des/sizes/sizes.c>; it should
compile cleanly on any hosted C99 implementation. Note that this does
*not* include Microsoft's C compiler, which only implements C89.
DES
-- Dag-Erling Smørgrav - d...@des.no
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
> what will be the size of data types(long, int, char, short) on a 64-
> bit architecture?
That is insufficient information. "64 bit" may refer to the size of
a *pointer*, not that of an integer. If the architecture had a 32-bit
history, that may affect the design to make upgrading easy.
Mimimum size (pick largest) Maximum size (pick smallest)
char 8 bits size of short
Since Unicode fits in 32 bits without multibyte encoding, it is
unlikely a char is larger than 32 bits.
Lots of stuff will break if char is larger than 8 bits.
short 16 bits size of int
size of char
A lot of networking stuff depends on the existence of a 16-bit type.
(which could be int16_t).
int 16 bits size of long
size of short
int is likely at least 32 bits in any architecture bigger than an Intel 386.
long 32 bits size of long long
size of int
If it's a "64-bit architecture", long is probably at least 64 bits.
long long 64 bits unlimited
size of long probably not more than 128 bits
You might have:
char/short/int/long/long long
8 / 16 / 32 / 64 / 64 or
8 / 16 / 32 / 64 / 128 or
8 / 16 / 64 / 64 / 128 or
8 / 16 / 32 / 32 / 64
Possible, but much less likely (except maybe in digital signal processor
chips), are:
32 / 32 / 32 / 64 / 64
64 / 64 / 64 / 64 / 64
64 / 64 / 64 / 64 / 128
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
On Wed, 2 Nov 2011 12:50:27 -0500 (CDT), Chiru Reddy
<chiru.0123456...@gmail.com> wrote:
>what will be the size of data types(long, int, char, short) on a 64-
>bit architecture?
Whatever the designer of your particular implementation decided they
should be. On many 64-bit hardware systems (architecture), it is
still possible to install a 32-bit implementation (compiler, linker,
and run-time library) and use it as it was intended.
sizeof(char) is always 1 by definition and the number of bits in that
one "byte" is documented in the CHAR_BITS macro. If you need to know
the size of an int, use the expression sizeof(int) and the compiler
will figure it out for you. In fact, using this expression will allow
simplify making your code portable between implementations with
different int sizes (giving it to someone else, upgrading your
compiler, etc).
You can get a lower bound (in terms of number of bits) on the size of
an int by looking at the INT_MAX macro.
-- Remove del for email
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
On Nov 2, 9:50 pm, Chiru Reddy <chiru.0123456...@gmail.com> wrote:
> what will be the size of data types(long, int, char, short) on a 64-
> bit architecture?
See the `limits.h' header file. Usually there are following values:
char - 1 byte, short - 2 bytes, int - 4 bytes, long - 8 bytes.
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
> sizeof(char) is always 1 by definition and the number of bits in that
> one "byte" is documented in the CHAR_BITS macro.
[...]
CHAR_BIT, not CHAR_BITS.
-- Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
> what will be the size of data types(long, int, char, short) on a 64-
> bit architecture?
Of course it depends on the implementation, within the
limitations demanded by the standard, as you have already
been told. I can just point out that there are three 64bit
programming models you need to consider: LP64, ILP64, LLP64,
where I = Int, L = Long, P = Pointer and 64 is the size in
bits of each (e.g. in LP64 the Long type and the Pointer
type are 64bits wide).
Data Type ILP64 LLP64 LP64
======================================
char 8 8 8
short 16 16 16
int 64 32 32
long 64 32 64
long long - 64 -
pointer 64 64 64
Most 64bit Unix-like OSs (included Linux, Solaris, FreeBSD/OpenBSD,
HP UX 11) have LP64 as programming model, while Windows uses the LLP64.
-- Vincenzo Mercuri | www.backbox.org -- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Vincenzo Mercuri <vincenzo.merc...@yahoo.it> writes:
> Chiru Reddy ha scritto:
>> what will be the size of data types(long, int, char, short) on a 64-
>> bit architecture?
> Of course it depends on the implementation, within the
> limitations demanded by the standard, as you have already
> been told. I can just point out that there are three 64bit
> programming models you need to consider: LP64, ILP64, LLP64,
> where I = Int, L = Long, P = Pointer and 64 is the size in
> bits of each (e.g. in LP64 the Long type and the Pointer
> type are 64bits wide).
> Data Type ILP64 LLP64 LP64
> ======================================
> char 8 8 8
> short 16 16 16
> int 64 32 32
> long 64 32 64
> long long - 64 -
> pointer 64 64 64
> Most 64bit Unix-like OSs (included Linux, Solaris, FreeBSD/OpenBSD,
> HP UX 11) have LP64 as programming model, while Windows uses the LLP64.
Those aren't the only possible models. I've worked on 64-bit systems
where short is 32 bits and int, long, and long long are all 64 bits
(Cray T3E), and where all four are 64 bits (Cray T90).
-- Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
-- comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.