C is not platform dependent.Why?

We know that C is not platform independent.but if we make a program on a operating system and copy the same program on other os without any changes then this program will run after compiling and will give the same answer.
so if same program will run on other os then why C is not platform independent.

Showing Answers 1 - 13 of 13 Answers

saurabh

  • Jul 13th, 2011
 

see, the size of int is 16 bits on some machines and 32 bits on some machines depend on os while using c where as in java the size of int is 32 bits that,s y its platform independent.

  Was this answer useful?  Yes

the_code

  • Aug 24th, 2011
 

Lets take example of Linux and Windows to explain this.
We say that C is platform dependent because

1. if you compile and build a C program code in windows, copy that .exe file to a linux machine, that .exe file will not run there.
2. In the same way if you compile the same program code on linux, you'll get a .out file which will not run on windows if directly copied there.

Aditya

  • Oct 2nd, 2011
 

platform dependency is not only in terms of software dependencies, it also depends on hardware.. here are some reasons,
1). i agree with #the_code.
2). run any graphics.h header file in windows in c program, then run that compiled program in Linux, the header file will not work, because graphics.h is not defined in Linux. there are more scenarios like that in C language.
3). there are some minimum no. of hardware requirements to run a C program, while it is not compulsory in java.

  Was this answer useful?  Yes

It is true that *some* programs can be compiled on other systems without any changes and produce the same outputs. "Hello, World" should work everywhere with no changes.

However, such trivially portable programs must meet both of the following criteria:

1. They must not make any assumptions about the sizes or representations of any data type beyond what is guaranteed by the language standard (e.g., chars will always be *at least* 8 bits wide, ints will always be *at least* 16 bits wide, etc.);

2. They must limit themselves to the data types and external libraries defined by the language standard (i.e., code that relies only on "stdio.h" will be trivially portable, whereas code that relies on "conio.h" or "unistd.h" will be limited to a specific platform).

Unfortunately, a lot of real-world C code must rely on platform-specific extensions to do anything interesting or useful; anything involving graphics, sound, networking, file system management, concurrency*, etc., must be done using either third-party or system-specific libraries and extensions.

* The draft C1X standard includes an optional threading library, so this may no longer be a limitation going forward.

  Was this answer useful?  Yes

Ramesh Yadav

  • May 4th, 2012
 

C is not platform dependent because it does not generate the uniform executables.
suppose if we have build C code and generated binary in Windows and this same binary will not work on Linux.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions