Size of data types in C?

S

siliconwafer

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

Richard Tobin

siliconwafer said:
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
 
7

7trackers

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..?
 
S

siliconwafer

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?
 
K

Keith Thompson

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.
 
W

Walter Roberson

(e-mail address removed) (Richard Tobin) writes:
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.
 
R

Richard Tobin

Nothing stops you writing a C compiler for Linux that provides 17-bit
ints and 18 bit pointers, but you won't sell many.
[/QUOTE]
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
 
N

Netocrat

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!
 
S

siliconwafer

"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?
 
W

Walter Roberson

"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."
 
V

vivek.sriwastava

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.
 
E

Emmanuel Delahaye

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.
 
A

Antonio Contreras

Walter said:
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.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top