473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 12097
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Shailesh | last post by:
One problem I've been wrestling with for a long time is how to use the C++ integral data types, vis-a-vis their size. The C++ rules guarantee that a char is at least 1 bytes, a short and int at...
3
by: Xiaobin Yang | last post by:
Why is the Class size 4-bytes instead of 1 byte as I intend to ? ================================= class BitTest { public: unsigned eightBits : 8; }; int main() {
79
by: syntax | last post by:
what is the size of a pointer? suppose i am writing, datatype *ptr; sizeof(ptr); now what does this sizeof(ptr) will give? will it give the size of the
6
by: dddddddd2444444 | last post by:
Hi,please help... It works fine when I define a 2-D array like char code. But it won't work when I try to define the array dynamically using a function. It just crashes. Does anyone know why?...
14
by: Agoston Bejo | last post by:
Hi, sorry about the multiple posting, technical difficulties.... ----- What does exactly the size of the int datatype depends in C++? Recenlty I've heard that it depends on the machine's...
2
by: Harry | last post by:
Good Day To all, When i am declaring a array for e.g char ....it means i am declaring array of 45 characters each of which has a maximum,minimum value limit or range...for example in...
111
by: Tonio Cartonio | last post by:
I have to read characters from stdin and save them in a string. The problem is that I don't know how much characters will be read. Francesco -- ------------------------------------- ...
5
by: Gary Wessle | last post by:
Hi I read some where about the order variables are declared in a class may help space optimization. find the size of bits a variable takes and declare them from biggest to the lowest. so in my...
6
by: Salman | last post by:
I want to know abt the size of the class using sizeof function. i have pasted 2 programs. Both gives different sizes of the class just by re- arranging the order of the private varibles. Tell me...
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.