473,698 Members | 2,635 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
12 3432
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.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.)


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
2335
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 are multiples of char, "so by definition the size of a char is 1." According to the rules, that...
31
3708
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
1923
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
5449
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)); printf("int : %d\n",sizeof(int));
1
2404
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# reference says that an int in C# is always 32 bits wide. It also specifies a specific number of bits...
4
1821
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 a type T (built-in or structure) whose pointer size is bigger than the sizeof (void *) ie sizeof (T...
26
1995
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
2390
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
8610
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.