Views
Advantages of running c in Linux/Unix-1
- 1 Comment
Welcome to my blog :-) .If you're new here, you may want to subscribe to my full RSS feed. Thanks for visiting!
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
1 2 3 4 5 6 7 8 9 | #include<stdio.h> 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??
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)
so the int variable ‘a’ can store a maximum value of 2147483647.Compare with this mere 32767..
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
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
1 Comments on this post
Trackbacks
-
Mehul said:
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.
May 16th, 2008 at 3:36 am








