473,396 Members | 1,916 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,396 software developers and data experts.

Size of data types in C?

Who decides size of data types in C?
Is it the:
1.C standard and hence the compilers
2.Operating System.

Nov 15 '05 #1
12 3403
In article <11*********************@g44g2000cwa.googlegroups. com>,
siliconwafer <sp*********@yahoo.com> wrote:
Who decides size of data types in C?
Is it the:
1.C standard and hence the compilers
2.Operating System.


Both, or rather all three.

The standard places constraints on the minimum size of several types.
The compiler can use any sizes it likes that meet these constraints,
but in order to interoperate with the operating system's libraries and
meet the expectations of users any successful compiler will have to
take the operating system into account.

Nothing stops you writing a C compiler for Linux that provides 17-bit
ints and 18 bit pointers, but you won't sell many.

-- Richard
Nov 15 '05 #2
what about the Hardware...Doesn't it maily rely on that...?

coz if the H/w is capable then only...the implementation is useful...?

right..?

Nov 15 '05 #3

7t*******@gmail.com wrote:
what about the Hardware...Doesn't it maily rely on that...?

coz if the H/w is capable then only...the implementation is useful...?

right..?

Which H/W *exactly* decides this?Is it the data width of memory where
the compiler stores the variables? OR is it the CPU regesters?

Nov 15 '05 #4
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
[...]
Nothing stops you writing a C compiler for Linux that provides 17-bit
ints and 18 bit pointers, but you won't sell many.


If by "17-bit ints" you mean, say, 18-bit ints with 1 padding bit,
that's true, as long as CHAR_BIT is either 9 or 18.

--
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.
Nov 15 '05 #5
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
Nothing stops you writing a C compiler for Linux that provides 17-bit
ints and 18 bit pointers, but you won't sell many.

If by "17-bit ints" you mean, say, 18-bit ints with 1 padding bit,
that's true, as long as CHAR_BIT is either 9 or 18.


But it's *Linux*, so you aren't going to -sell- many of *anything*
(discounting the "Linux for Dummies" books and the Slashdot
merchandise.)
Some of my co-workers are modelling the spread of infectious diseases.
(Seriously so.) As best I can tell, the same techniques can be
used to model the spread of Linux.
Nov 15 '05 #6
On Mon, 10 Oct 2005 19:43:35 +0000, Walter Roberson wrote:
Some of my co-workers are modelling the spread of infectious diseases.
(Seriously so.) As best I can tell, the same techniques can be used to
model the spread of Linux.


So Microsoft were right - the GPL _is_ viral!

--
http://members.dodo.com.au/~netocrat
Nov 15 '05 #7
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
Nothing stops you writing a C compiler for Linux that provides 17-bit
ints and 18 bit pointers, but you won't sell many.
If by "17-bit ints" you mean, say, 18-bit ints with 1 padding bit,
that's true, as long as CHAR_BIT is either 9 or 18.


Much more likely is that CHAR_BIT is 17 and pointers have 16 padding
bits :-)

-- Richard
Nov 15 '05 #8
"what about the Hardware...Doesn't it maily rely on that...? "
Which H/W *exactly* decides this?Is it the data width of memory where
the compiler stores the variables? OR is it the CPU regesters?

Reply
MyAnswer?

Nov 15 '05 #9
In article <11**********************@g49g2000cwa.googlegroups .com>,
siliconwafer <sp*********@yahoo.com> wrote:
"what about the Hardware...Doesn't it maily rely on that...? " Which H/W *exactly* decides this?Is it the data width of memory where
the compiler stores the variables? OR is it the CPU regesters? Reply
MyAnswer?


Oh, I thought your question was rhetorical.

For the same hardware and the same OS, there might be several
compiler options that lead to different type sizes. Not all
of those are necessarily going to be implemented as pure hardware
operations. A 128 bit "long long" on a machine with 64 bit
registers might be processed through library calls or through
standard multi-precision techniques for simpler operations.

Integral type sizes chosen for a particular combination of
hardware + OS + compiler + flags
will -usually- involve a power-of-2 multiplied by the native
operation size, as those sizes are usualy easier to program.

Floating point type sizes, if not using the native size, are
more likely to be reliant on the politics of whatever the IEEE
committee has defined.

In any case, operation sizes supported will be strongly
influenced by marketting considerations. If your potential
customer is the National Weather Office, and they tell you
they want a 240 bit float synthesized from three 80-bit registers,
and they say, "We have $47 million for this project if you can
install 3 of them before the next hurricane season", then
you answer "Yes, certainly", not "But our longest hardware
register is only 64 bits."
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
Nov 15 '05 #10
hi,
It is basicaly decided by the compiler.
OS simply provide the base for the compiler and nothing else . But it
is mutual because if OS is not capable enough to handle the request of
compiler then it is not possible for compiler to get done any work.
For example turbo C takes only two bytes in case of int while VC++
takes 4 byte fopr the same int.
Or take one more example of java for the same platform turbo C
allocate only two byte while java allocate 4 bytes.

Nov 15 '05 #11
siliconwafer a écrit :
Who decides size of data types in C?
Is it the:
1.C standard and hence the compilers
2.Operating System.


It's more subtle...

- The C-standard doen't define the data types i terms of width but
rather in terms of range. It gives minimum ranges for each type :

Type Minimum Maximum
char 0 127
unsigned char 0 255
signed char -127 127
[signed] short -32767 32767
usigned short 0 65535
[signed] int -32767 32767
unsigned [int] 0 65535
[signed] long [int] -2147483647 2147483647
unsigned long [int] 0 4294967295

[fixed font required]

- The implementation (the processor and the way it is used by the
system) fixes the actual number of bits of each type, so that the
minimum C-requirements are reached.

For example:

x86 real and extended mode (BIOS, MS-DOS, Windows 3x):

char is 8-bit
short is 16-bit
int is 16-bit
long is 32-bit

Same processor but in protected mode (aka '32-bit') as used by Win32,
Linux etc.:

char is 8-bit
short is 16-bit
int is 32-bit
long is 32-bit

Now, if you play with a Texas Instrument DSP like TMS320C54:

char is 16-bit
short is 16-bit
int is 16-bit
long is 32-bit

etc. It depends on the hardware capabilities.
Nov 15 '05 #12
Walter Roberson wrote:
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.org> wrote:
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
Nothing stops you writing a C compiler for Linux that provides 17-bit
ints and 18 bit pointers, but you won't sell many.

If by "17-bit ints" you mean, say, 18-bit ints with 1 padding bit,
that's true, as long as CHAR_BIT is either 9 or 18.


But it's *Linux*, so you aren't going to -sell- many of *anything*
(discounting the "Linux for Dummies" books and the Slashdot
merchandise.)


Arguable.
Some of my co-workers are modelling the spread of infectious diseases.
(Seriously so.) As best I can tell, the same techniques can be
used to model the spread of Linux.


Or the spread of technological innovations (movile phones, digital
cameras...), or the spread of nenufars in a lake, or the growth rate of
a bacteria population, or the spread of hoaxes over email users, or the
spread of ...

The logistical equation can be applied in many many situations.

Nov 15 '05 #13

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...
31
by: bilbothebagginsbab5 AT freenet DOT de | last post by:
Hello, hello. So. I've read what I could find on google(groups) for this, also the faq of comp.lang.c. But still I do not understand why there is not standard method to "(...) query the...
15
by: puzzlecracker | last post by:
Got Confused on the interview with memory alligment questions... PLEASE HELP -- How much bytes of memory will structs below take on 32 bit machine? What about 64 bit machine? Why is it different?...
35
by: Sunil | last post by:
Hi all, I am using gcc compiler in linux.I compiled a small program int main() { printf("char : %d\n",sizeof(char)); printf("unsigned char : ...
1
by: Neil Zanella | last post by:
Hello all, In C and C++ a primitive data type is represented by a minimum number of bits as defined by the corresponding standard. For instance an int is assumed to be at least 16 bits on all...
4
by: Roy | last post by:
I have an object with array of some data types. How do I get the number of bytes for it in managed code? The underlying data types could be primitive types or userdefined structures. For example I...
11
by: subramanian100in | last post by:
Given that the sizes of pointers to different data types(built-in or structures) can be different, though malloc returns a void *, it is assigned to any pointer type. The language allows it. From...
26
by: rao | last post by:
On some of the compilers integer size is 2 and on some other it is 4 bytes. My doubt is who decides the size of the integer? is it plainly the compiler? Does OS or Processor also has any control...
2
by: zeeshan708 | last post by:
Is it the compiler that determines the size of the data types (e.g an int is of 2 bytes or of 4 bytes ) or does it depends on the computer's hardware that shall determine the size of the data types.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.