who decides the size of a data type?

R

rao

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 in deciding the size of such
data types?
 
W

Willem

rao wrote:
) On some of the compilers integer size is 2 and on some other it is 4
) bytes.

And on some, it is 8. And on very few others, it's another number.

) My doubt is who decides the size of the integer?

In India, do 'doubt' and 'question' translate to the same word ?
In any case, the right word to use in English is 'question'.

) is it plainly the compiler?
) Does OS or Processor also has any control in deciding the size of such
) data types?

Usually, the compiler decides the size, based on what the OS and/or
the processor have to offer. I think the C standard even strongly
suggests that 'int' be the size that is 'most natural' to the system.

However, it is ultimately the compiler that makes the decision.
For example, there are systems that have 'natural' 8-byte integers,
but a lot of C compilers still use 4-byte int types.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
G

Gordon Burditt

On some of the compilers integer size is 2 and on some other it is 4

There are other possibilities. Don't be surprised to see 8 in the
future. And 3 isn't impossible.
My doubt is who decides the size of the integer?

The compiler writer. But some choices make his job easier than others.
is it plainly the compiler?
Does OS or Processor also has any control in deciding the size of such
data types?

The choice is heavily influenced by such things as the size of
machine registers, the instruction set of the machine, and the
interface the OS provides. It is possible, for example, to provide
an integer of size 3 (3 11-bit characters) on an Intel x86 machine,
but the code will not be very efficient and it may be wasteful of
storage. You can emulate one machine on another, and generate code
for the emulated machine, but that's a lot of effort and no guarantee
of efficiency.
 
S

santosh

rao said:
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 in deciding the size of such
data types?

Generally both. Most compilers map C's numeric types to the underlying
hardware types in the most efficient manner possible. Usually the type
char is aliased to the machine's byte while the type int corresponds to
the native word of the processor. Other types may vary. Main concerns
for implementors are to avoid breaking existing code and to provide as
much efficiency as possible.

The Standard of course specifies the minimum ranges for these types
which every conforming compiler must adhere to.
 
W

Wolfgang Draxinger

santosh said:
Usually the type char is aliased to the machine's
byte while the type int corresponds to the native word of the
processor.

Not to forget that some architectures provide special functions
to operate on strings, which have some constraints on the type
(like each element of a string being a byte of 8 bits). It makes
quite some sense if an C implementation uses this type then for
char.

Wolfgang Draxinger
 
I

Ian Collins

Willem said:
) is it plainly the compiler?
) Does OS or Processor also has any control in deciding the size of such
) data types?

Usually, the compiler decides the size, based on what the OS and/or
the processor have to offer. I think the C standard even strongly
suggests that 'int' be the size that is 'most natural' to the system.
On a hosted environment, the OS dictates the size. In order to work
with the system's headers and libraries, compilers have to follow the
platform's standards.
 
L

Lew Pitcher

Ian said:
On a hosted environment, the OS dictates the size. In order to work
with the system's headers and libraries, compilers have to follow the
platform's standards.

But this may become a "chicken-and-egg" problem on certain platforms, where
the OS is easily rebuilt with a conforming C compiler (i.e. recompiling a
32bit OS into a 64bit OS using a suitable compiler on a 32bit system).
Additionally, some platforms support multiple concurrent "views" of the
environment, such that two or more distinct size choices are available at
execution time (witness some 64bit platforms that execute /either/ 64bit or
32bit code (with corresponding differences in data type sizes)
simultaneously).


--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
K

Keith Thompson

Ian Collins said:
On a hosted environment, the OS dictates the size. In order to work
with the system's headers and libraries, compilers have to follow the
platform's standards.

Typically, yes. But if the headers and libraries are part of the C
implementation rather than part of the OS, then the C implementation
can make whatever choices it likes, as long as it's consistent.

Note, for example, that the MinGW implementation under Windows uses a
different size and representation for long double than the one the OS
prefers. This causes problems (since the libraries *are* part of the
OS, the implementation as a whole is inconsistent), but in theory
those problems could be solved.
 
W

Willem

Lew wrote:
) Ian Collins wrote:
)
)> Willem wrote:
)>>
)>> ) is it plainly the compiler?
)>> ) Does OS or Processor also has any control in deciding the size of such
)>> ) data types?
)>>
)>> Usually, the compiler decides the size, based on what the OS and/or
)>> the processor have to offer. I think the C standard even strongly
)>> suggests that 'int' be the size that is 'most natural' to the system.
)>>
)> On a hosted environment, the OS dictates the size. In order to work
)> with the system's headers and libraries, compilers have to follow the
)> platform's standards.
)
) But this may become a "chicken-and-egg" problem on certain platforms, where
) the OS is easily rebuilt with a conforming C compiler (i.e. recompiling a
) 32bit OS into a 64bit OS using a suitable compiler on a 32bit system).
) Additionally, some platforms support multiple concurrent "views" of the
) environment, such that two or more distinct size choices are available at
) execution time (witness some 64bit platforms that execute /either/ 64bit or
) 32bit code (with corresponding differences in data type sizes)
) simultaneously).

I think 'the OS' in this case is meant to be the whole package, especially
the system headers and libraries. However, an OS may supply multiple sets
of those, possibly with different sizes for int.

Besides which, a C compiler may come packaged with libraries and system
headers of its own.

But, in general, the compiler takes its cue from the OS.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
R

Richard Heathfield

Ian Collins said:
On a hosted environment, the OS dictates the size. In order to work
with the system's headers and libraries, compilers have to follow the
platform's standards.

I have a machine here on which are installed several implementations. Most
of these use 32-bit ints, but a couple use 16-bit ints. So is the OS
dictating 16-bit, or 32-bit?
 
I

Ian Collins

Richard said:
Ian Collins said:


I have a machine here on which are installed several implementations. Most
of these use 32-bit ints, but a couple use 16-bit ints. So is the OS
dictating 16-bit, or 32-bit?
Whichever is required to use the services of the OS.

Any implementation is free to provide its own headers and libraries and
choose its own sizes, but it then restricts its self to building
applications that do not use any external services provided by the OS.
 
I

Ian Collins

Lew said:
But this may become a "chicken-and-egg" problem on certain platforms, where
the OS is easily rebuilt with a conforming C compiler (i.e. recompiling a
32bit OS into a 64bit OS using a suitable compiler on a 32bit system).
Additionally, some platforms support multiple concurrent "views" of the
environment, such that two or more distinct size choices are available at
execution time (witness some 64bit platforms that execute /either/ 64bit or
32bit code (with corresponding differences in data type sizes)
simultaneously).
They do, but they employ standard models for their 32 and 64 bit
personalities. Providing a compiler for windows that used the LP64
model or a UNIX compiler that used the LLP64 model would be possible,
but pointless.
 
G

Gordon Burditt

On a hosted environment, the OS dictates the size. In order to work
with the system's headers and libraries, compilers have to follow the
platform's standards.

An OS, especially one not written in C in the first place (this
applies to the first version of UNIX, too, which was originally
written in assembly language), may come with *NO* system headers
(at least not in C) and *NO* C-callable libraries (it might instead
use assembly-language macros or routines written in some other
language). In that case, it's up to the C implementor to supply
those headers (possibly translated from another language) and
libraries (possibly just "glue" interface routines). If there's
not a popular C API to the OS, the implementor might have to supply
one.

It can still take guidance from the OS (although the more important
guidance is likely from the CPU architecture). Some systems provide
several different choices on the same OS, particularly with respect
to pointer sizes, and provide different sets of libraries for each.
See, for example, the different MS-DOS memory models, which have
different combinations of 16-bit and 32-bit data and function
pointers. I think some compilers also provide a 32-bit mode with
32-bit ints for MS-DOS. You can't mix compiled or standard code
from different models (implementations): they all have to come from
the same one (non-standard features involving the "near" and "far"
pseudo-keywords made some mixing possible).
 
I

Ian Collins

{I you are going to reply to one of my posts, please stop being so
arrogant as to ignore attributions]

Gordon said:
It can still take guidance from the OS (although the more important
guidance is likely from the CPU architecture). Some systems provide
several different choices on the same OS, particularly with respect
to pointer sizes, and provide different sets of libraries for each.
See, for example, the different MS-DOS memory models, which have
different combinations of 16-bit and 32-bit data and function
pointers. I think some compilers also provide a 32-bit mode with
32-bit ints for MS-DOS. You can't mix compiled or standard code
from different models (implementations): they all have to come from
the same one (non-standard features involving the "near" and "far"
pseudo-keywords made some mixing possible).
Exactly, the compilers follow the OS.
 
G

Gordon Burditt

On a hosted environment, the OS dictates the size. In order to work
Exactly, the compilers follow the OS.

MS-DOS did not provide any C system headers or libraries. It's hard to follow
the OS when the OS doesn't provide direction, which is one reason why so many
different directions were followed by MS-DOS C compilers.
 
I

Ian Collins

Who said this?
MS-DOS did not provide any C system headers or libraries. It's hard to follow
the OS when the OS doesn't provide direction, which is one reason why so many
different directions were followed by MS-DOS C compilers.
 
C

CBFalconer

Willem said:
And on some, it is 8. And on very few others, it's another number.


In India, do 'doubt' and 'question' translate to the same word ?
In any case, the right word to use in English is 'question'.

No, Willem. The phrases "I have a doubt" and "my doubt" are quite
ordinary English usage. They are more popular in India than in
most other English speaking areas. I concede that many native
English speakers don't recognize that, but their ignorance is of no
concern. You, apparantly, are Dutch, and have no reason to
recognize the usage.

At any rate, apply my favorite exorcism. Sedulously eschew
obfuscation. :)
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top