473,569 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3412
In article <11************ *********@g44g2 000cwa.googlegr oups.com>,
siliconwafer <sp*********@ya hoo.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...Does n'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...Does n'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_Keit h) 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.or g>,
Keith Thompson <ks***@mib.or g> 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.or g>,
Keith Thompson <ks***@mib.or g> 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...Does n'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************ **********@g49g 2000cwa.googleg roups.com>,
siliconwafer <sp*********@ya hoo.com> wrote:
"what about the Hardware...Does n'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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2309
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 least 2 bytes, and a long at least 4 bytes. The rules also define a size precedence to the types. In Stroustrup's book, it says that all type sizes...
31
3686
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 malloc package to find out how big an allocated block is". ( Question 7.27) Is there somwhere explained why - because it would seem to me, that free()
15
1910
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? (if it's relevent, use standard size of datatypes) a) Code: struct
35
5420
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 : %d\n",sizeof(unsigned char)); printf("short : %d\n",sizeof(short)); printf("unsigned short : %d\n",sizeof(unsigned short));...
1
2401
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 platform where in practice an int is 16 bits on the arcane 16 bit machines and 32 bits on the most commonly used 32 bit machines. However, my C#...
4
1816
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 have an integer array boxed in object.
11
518
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 this, can I conclude that the size of (void *) should be the maximum ? If this is not the case, consider the following scenario. Suppose there is...
26
1965
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 in deciding the size of such data types?
2
2381
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
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.