Advantages of running c in Linux/Unix-1

C is strongly linked with linux/unix .The kernel of Unix/Linux is written in C.Running C in linux/unit has several advantages .The most important among it is full word length utilization.
Consider the following C program

#include
int main()
{
int a;
float b;
printf("Size of int datatype =%d bits\n",(sizeof(a)*8));
printf("Size of float datatype =%d bits\n",(sizeof(b)*8));
return 1;
}

sizeof() returns the amount of bytes that the variable is awarded

We want the answer in bits,hence we have to multiplied it by 8 (1 byte=8bits)
now run this c program in turbo c in windows
the output will be


Size of int datatype=16 bits
Size of float datatype =32 bits

Even though your computer is 32 or 64 bit computer, Turbo C is utilizing only 16 bits to int which should have been 32 bits(Int is allocated with a space equal to wordlength of the computer)

now run the above c program in linux
the output will be

Size of int datatype=32 bits
Size of float datatype =64 bits

^^if your processor is 32 bit


Size of int datatype=64 bits
Size of float datatype =128 bits

^^if your processor is 64 bit

Ok…running C program in linux/unix utilizes full word length.what’s it’s use for me?? :idea:

The maximum number of singed int datatype(normal int) that can be accomodated if you run c in windows is ((2^15)-1)=32767
that means if ‘a’ is made to store number greater than 32767 it will cause data overflow and you will get garbage values.(Read How C Compiler decides the Garbage values in case of data overflow for more information)

Now ,lets take the scenario in linux/unix

The maximum number of singed int datatype(normal int) that can be accomodated if you run c in linux is ((2^31)-1)=2147483647 (assuming your comp is 32 bit) :shock:

so the int variable ‘a’ can store a maximum value of 2147483647.Compare with this mere 32767.. :cool:

This is for int datatype consider other datatypes such as float,long double,double,long int etc..
Imagine how many big values it can store :shock:

So you can play with larger values if you run a C program in linux/unix.
Apart from this the speed of execution will be more than double since it utilizes full available word length.


You may also like

Find out what I am doing by following me on Twitter... Tweet This Post!

Here’s what they said...

  1. Mehul

    - May 16th, 08

    Now doesn’t that hold true for 32-bit compilers on windows too? It should be the same if you use mingw or VS on Windows since they are 32-bit compilers too.

  2. name

    - Sep 1st, 08

    Hi!,

  3. name

    - Sep 1st, 08

    Good day!,

  4. name

    - Sep 1st, 08

    Hello!,

Leave a Reply

Comment on the next level:

- Enter your info on the left

- Create an avatar with Gravatar!