469,287 Members | 2,628 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

size of int and char

What is the size of int on 64-bit computers ?
Can char have minimal size different from signed char ?

Jul 2 '07 #1
14 11593
ra****@op.pl wrote On 07/02/07 13:13,:
What is the size of int on 64-bit computers ?
sizeof(int). All that can be said with certainty is
that this value is at least ceil(16/CHAR_BIT); it might
be greater.
Can char have minimal size different from signed char ?
No. All of sizeof(char), sizeof(signed char), and
sizeof(unsigned char) are equal to 1.

--
Er*********@sun.com
Jul 2 '07 #2
ra****@op.pl wrote:
What is the size of int on 64-bit computers ?
Whatever the implementation uses, as long as it includes at least the
range the standard requires for ints (-32767 through +32767). The only
answers are sizeof(int) or sizeof(int)*CHAR_BIT, depending on what your
question actually is.
Can char have minimal size different from signed char ?
sizeof(char) = sizeof(unsigned char) = sizeof(signed char) = 1
by definition.
Jul 2 '07 #3

<ra****@op.plha scritto nel messaggio news:11*********************@n60g2000hse.googlegro ups.com...
What is the size of int on 64-bit computers ?
sizeof(int)
Can char have minimal size different from signed char ?
No. They both have size 1, by definition.
Jul 2 '07 #4
On 2 Lip, 21:10, "Army1987" <please....@for.itwrote:
<raf...@op.plha scritto nel messaggionews:11*********************@n60g2000hse. googlegroups.com...What is the size of int on 64-bit computers ?

sizeof(int)
I meant if sizeof(int) and size of registers are equal.
Jul 2 '07 #5
ra****@op.pl writes:
On 2 Lip, 21:10, "Army1987" <please....@for.itwrote:
><raf...@op.plha scritto nel
messaggionews:11*********************@n60g2000hse .googlegroups.com...
>>What is the size of int on 64-bit computers ?

sizeof(int)

I meant if sizeof(int) and size of registers are equal.
What's a "register"?

The C standard (which defines the C language, which is what we discuss
here) doesn't say anthing about "registers". (The "register" keyword
is merely a hint that access to a variable should be quick; it also
means you can't take its address.) The standard also has no concept
of a "64-bit system". For that matter, even in general there's no
univerally agreed definition of what a "64-bit system" is.

Within the parameters set by the standard, the sizes of the
fundamental types are decided by the implementers (compiler authors),
in any way they choose.

I've worked on "64-bit systems" with 32-bit ints, and on other "64-bit
systems" with 64-bit ints.

There is a drawback to making int 64 bits. Assuming 8-bit characters,
it leaves a gap in the integer type system. There's only one type
bigger than char and smaller than int, namely short, which means that
either there won't be a 16-bit type, or there won't be a 32-bit type.
(I'm ignoring the unsigned variants; they're required to be the same
size as the corresponding signed types.) I think that's part of the
reason that many 64-bit implementations have kept int at 32 bits
rather than 64. Another consideration is compatibility with 32-bit
systems; well-written software shouldn't care, but not all software is
well-written.

But the decision is entirely up to the implementer. int has to be at
least as wide as char and short, no wider than long (and long long, if
it exists; it's required in C99), and at least 16 bits.

--
Keith Thompson (The_Other_Keith) 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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 2 '07 #6
raf...@op.pl wrote:
"Army1987" <please....@for.itwrote:
<raf...@op.plha scritto
>
What is the size of int on 64-bit computers ?
sizeof(int)

I meant if sizeof(int) and size of registers are equal.
The C language doesn't specify the 'size' of hardware
registers, so it's difficult to know what you mean by size
of registers. I presume you're not talking about the size
of register qualified objects.

In any case, the answer remains the same from the point
of view of a C program. The size of an int is precisely
sizeof(int) bytes.

A C byte needs to be at least 8 bits. The minimum required
range of an int means it must have at least 16 bits. Beyond
that, an implementation can pick and choose what sizes it
wants. That size is influenced by the architecture, but it
needn't be a slave to it.

--
Peter

Jul 2 '07 #7
Keith Thompson <k...@mib.orgwrote:
...
The C standard (which defines the C language, which is
what we discuss here) doesn't say anthing about "registers".
5.1.2.3p12 (Example 4) may be non-normative, but it clearly
talks about registers as something other than an abstract
storage class.
(The "register" keyword is merely a hint that access to a
variable should be quick; it also means you can't take its
address.)
Was that keyword and storage class randomly named?

--
Peter

Jul 2 '07 #8
Peter Nilsson <ai***@acay.com.auwrites:
Keith Thompson <k...@mib.orgwrote:
>...
The C standard (which defines the C language, which is
what we discuss here) doesn't say anthing about "registers".

5.1.2.3p12 (Example 4) may be non-normative, but it clearly
talks about registers as something other than an abstract
storage class.
You're right, I wasn't aware of that example. On the other hand, the
wording there specifically says that the use of registers doesn't
affect the semantics of the code.
>(The "register" keyword is merely a hint that access to a
variable should be quick; it also means you can't take its
address.)

Was that keyword and storage class randomly named?
Certainly not; the original intent was that a variable declared with
the "register" keyword should, if possible, be stored in a register.
But the current definition has no trace of that meaning, other than
the name.

--
Keith Thompson (The_Other_Keith) 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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 2 '07 #9
sid
On Jul 2, 10:13 pm, raf...@op.pl wrote:
What is the size of int on 64-bit computers ?
size of int is 4 bytes on my AMD athlon 64 bit machine

Jul 3 '07 #10
sid <ki***********@gmail.comwrites:
On Jul 2, 10:13 pm, raf...@op.pl wrote:
>What is the size of int on 64-bit computers ?

size of int is 4 bytes on my AMD athlon 64 bit machine
sizeof(int) could easily be 8 on the same machine with a different
compiler or operating system, or even with different options to the
same compiler.

See the other responses in this thread for a detailed explanation.

--
Keith Thompson (The_Other_Keith) 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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 3 '07 #11

"Peter Nilsson" <ai***@acay.com.auha scritto nel messaggio news:11**********************@j4g2000prf.googlegro ups.com...
Keith Thompson <k...@mib.orgwrote:
>...
The C standard (which defines the C language, which is
what we discuss here) doesn't say anthing about "registers".

5.1.2.3p12 (Example 4) may be non-normative, but it clearly
talks about registers as something other than an abstract
storage class.
>(The "register" keyword is merely a hint that access to a
variable should be quick; it also means you can't take its
address.)

Was that keyword and storage class randomly named?
It is irrelevant here. You can also have
struct Verylarge {
long integer;
long double real;
void *pointer;
void (*function)();
};
register struct Verylarge a;
even if it won't fit in a register. (And you can also have register
arrays, but since you can't take the address of them (not even
implicitly) the only thing you'll be able to do with them is to
measure their size with sizeof.)
Jul 3 '07 #12
ra****@op.pl wrote:
"Army1987" <please....@for.itwrote:

What is the size of int on 64-bit computers ?
>sizeof(int)

I meant if sizeof(int) and size of registers are equal.
sizeof(int)

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jul 3 '07 #13
"sid" <ki***********@gmail.comwrote in message
news:11**********************@g37g2000prf.googlegr oups.com...
On Jul 2, 10:13 pm, raf...@op.pl wrote:
>What is the size of int on 64-bit computers ?

size of int is 4 bytes on my AMD athlon 64 bit machine
With the particular implementation you're testing, perhaps. Others running
on the same CPU may be 2 or 8 bytes. It has little to do with the CPU; it's
all about the particular ABI you're targeting...

S

--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov
--
Posted via a free Usenet account from http://www.teranews.com

Jul 3 '07 #14

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
sid <ki***********@gmail.comwrites:
>On Jul 2, 10:13 pm, raf...@op.pl wrote:
>>What is the size of int on 64-bit computers ?

size of int is 4 bytes on my AMD athlon 64 bit machine

sizeof(int) could easily be 8 on the same machine with a different
compiler or operating system, or even with different options to the
same compiler.

See the other responses in this thread for a detailed explanation.
'could be', yes, but 'is', probably not.

that is why I, personally, find this thread annoying.
now, on x86-64, will anyone make sizeof(int)==8?...
I would doubt it.

64-bit operations are more expensive than 32 bit ones (at least in terms of
more often requiring a REX prefix, ...).

now, on a different arch? maybe, but also likely not.
and, if a compiler writer did do this?
well, then, a good deal of existing apps would break.

usually, when targeting a particular arch, we make a few assumptions, such
as the sizes of various types, ...

and, people will not change these, lest they risk the resultant crap storm.

and what of 'sizeof(int)==2'? well, those targeting something like dos will
tend to know at least this much. "oh wow, I am targetting dos, I feel like
malloc'ing a 1MB buffer", errm, no...

the compiler has the right and moral obligation to ram its foot up the dev's
backend...
after all, all this is part of why we 'port' apps.

a good deal of apps, regularly make certain assumptions, regardless of
whatever the spec may happen to say.
now, if we were talking about sizeof(long), well then, this one does vary in
this case...
theory is one thing, practice is another...

--
Keith Thompson (The_Other_Keith) 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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Jul 3 '07 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Shailesh | last post: by
3 posts views Thread by Xiaobin Yang | last post: by
79 posts views Thread by syntax | last post: by
14 posts views Thread by Agoston Bejo | last post: by
2 posts views Thread by Harry | last post: by
111 posts views Thread by Tonio Cartonio | last post: by
5 posts views Thread by Gary Wessle | last post: by
6 posts views Thread by Salman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.