Is C Language Platform Independent?

is c platform independent?as i think it is.but it is compiler dependend.my statement is right or wrong?

Replies

  • [Prototype]
    [Prototype]
    Yes C is platform independent. However, it doesn't mean you can run any code on any machine. It depends on the resources you've used in the code but generally speaking, yes its platform independent.
  • pawan.kumar123
    pawan.kumar123
    No C is not platform independent. Platform means Operating system + hardware and with the change of this combination you need different vendor specific programs to convert you c code into a machine executable code. So for windows you need a different program(compiler) but with Linux you need different compiler to convert your c code into machine executable code form. For each platform( operating system + hardware resources) you need different compiler programs to get executable code from c programs. That's why c is not platform independent
  • Abhishek Rawal
    Abhishek Rawal
    pawan.kumar123
    for windows you need a different program(compiler) but with Linux you need different compiler to convert your c code into machine executable code form
    No Sir,
    C is platform dependent , i accept.
    But, Its difficult to say that "windows need different compiler than Linux to execute the program".
    If you check out most of released compilers, 90% are 'em are compatible to both.
    & The most popular one - GCC, GNU compiler is available for both Linux & Windows.
    There are many more compilers available, some are with IDEs & some not. Some Compilers are maintained regularly & some not.
    Maintained ones becomes popular & the out-of-date compilers become extinct.
    For list of compilers :: List Of Compilers C Compilers
  • [Prototype]
    [Prototype]
    How you're saying that C language is platform dependent?

    If you can make programs for Windows, Linux, AVR with same syntax and language constructs, using same compiler (GCC), then what is making it platform dependent?

    True that you cannot directly port a windows program to Linux, but that doesn't mean its platform dependent.
  • greatcoder
    greatcoder
    #-Link-Snipped-# No C language is not platform independent.
    I think following points will give u good picture:

    1) If you have written a code on one platform, then u need to compile the same
    code on different platforms separately if want run your code on them.

    2) Some internal library functions rely on the platform OS system calls
    and may not work the same way on all platforms.

    3) Also C language behaves differently on different platforms, for example
    some architectures may follow different schemes for their data-path flow, different
    little/big endian terminology.
  • sulochana anand
    sulochana anand
    I think it is good discussable point that c is platform independent or not.I read in a book that c is portable.and portable means moovable.its true that on diffrent os it gives diffrent result but slightly diffrent.i think its platform independent.what u say?
  • Sreejith T
    Sreejith T
    sulochana anand
    is c platform independent?as i think it is.but it is compiler dependend.my statement is right or wrong?
    very well C is not suitable to be run on every machines.....
  • sulochana anand
    sulochana anand
    i just wan to ask did u check it?
  • Sreejith T
    Sreejith T
    sulochana anand
    i just wan to ask did u check it?
    No I have read it on THE COMPUTER ACTIVE magazine an year ago
  • Rahulbsb
    Rahulbsb
    sulochana anand
    I think it is good discussable point that c is platform independent or not.I read in a book that c is portable.and portable means moovable.its true that on diffrent os it gives diffrent result but slightly diffrent.i think its platform independent.what u say?
    This discussion has gone all over the place now..
    Here's my question––
    If u write a C program using all the standard C libraries that are common to all platforms (Be it Unix(any flavor) or Windows)e.g--stdio.h or math.h or string.h or stdlib.h and so on..and compile it using a standard compiler (lets take gcc for this discussion's sake) and run it on any one standard CPU arch (X86 for instance 64 bit) why wouldn't the binary run across different machines matching all the above criteria? e.g when i compile a c code (making use of standard libraries--stdio,stdlib etc) using gcc on my mac (having X86 arch) and create a binary file, shouldn't it be capable of running the bin file on a linux or windows running on an X86 machine (same as my mac's) using the very same gcc runtime.. I'm not using any mac specific system calls (i use standard C libs) that would become unrecognized in a differing platform.. During the build process of this binary (comprising— preprocessing, compilation,generating assembly code which assembles into object code and then finally standard C built-in library .o files linking with the main.o) there has been no platform specific system calls or propreitary API used. What i'm getting at is that for building the C binary, i have used a common gcc compiler, a common microprocessor arch, and no platform specific system calls (e.g. including Linux's sys/io.h wouldn't even compile on any non linux based box let alone running it)
  • Rahulbsb
    Rahulbsb
    Rahulbsb
    This discussion has gone all over the place now..
    Here's my question––
    If u write a C program using all the standard C libraries that are common to all platforms (Be it Unix(any flavor) or Windows)e.g--stdio.h or math.h or string.h or stdlib.h and so on..and compile it using a standard compiler (lets take gcc for this discussion's sake) and run it on any one standard CPU arch (X86 for instance 64 bit) why wouldn't the same binary run across different machines matching all the above criteria? e.g when i compile a c code (making use of standard libraries--stdio,stdlib etc) using gcc on my mac (having X86 arch) and create a binary file, shouldn't it be capable of running the bin file on a linux or windows running on an X86 machine (same as my mac's) using the very same gcc runtime.. I'm not using any mac specific C library function or routine that triggers Mac OS specific system calls (i use standard C libs—stdio.h or stdlib.h ) that would become unrecognized in a differing platform.. During the build process of this binary (comprising— preprocessing, compilation,generating assembly code which assembles into object code and then finally standard C built-in library .o files linking with my main.o) there has been no platform specific library used that would do any platform specific system calls or propreitary API used. What i'm getting at is that in order for building the C binary, i have used a common gcc compiler, a common microprocessor arch, and no platform specific system calls (e.g.#including Linux's sys/io.h in a C source file wouldn't even compile on any non linux based box let alone running it.. The compiler will throw a fit on Mac OS or Windows as it won't be able to locate and resolve sys/io.h )
    So now getting back to query,, what is it that i'm missing?? Does the GCC runtime differ from OS to OS? Then the question is— what happens during when the C output file is being loaded in memory by the program loader part of the operating system? If there are certain platform runtime routines (dynamic libraries) that run on the specific machine when executing the output (post-build linking)... KEEP IN MIND.. ALL THRU THIS DISCUSSION WE HAVE BEEN TAKING INTO CONSIDERATION THE SAME CPU ARCHITECTURE..So pls don't say "it is due to differences in architecture"..

You are reading an archived discussion.

Related Posts

hi ..... friends i have an great idea to make final year project on "irrigation system using venturi for fertiliser distribution" but i have problem that i didn't get the...
A Gold Medal (Full Moon) gets into the act:
HAPPY FRIENDSHIP DAY CEans 😀 !!
So, recently I heard someone saying to me that mind has the potential power of controlling many things and doing extraordinary things. Take this instance, Somebody is extremely fat ,...
Indian boxer Vikas Krishan who was earlier declared winner, Now crashed out of the game after the decision was in the favor of his American opponent Errol Spence.The boxing team...