This Question is not programming related but rather important for all compiler related programming languages especially the Language C.

what is portabily?

since my graduation i have been taught C is not 100 % portable language.

but i dint get any satisfactory answers for,not 100 % portable?
where its lagging and why can't we make it 100 % portable?

How a compiler generates the portable code for all the processors

Assembly language is considered as non portable language because the instruction are understandable only by the specific processor.

but how a compiler is able to generate code that is understandable by all the processors.

when i install a compiler i dont worry on what processor my system runs ( i only worry about OS, what OS does to compiler?)

again the OS may run on different processors.

but how a particular comipler is able to generate code that almost works on all processors with minor or few modifications.

i believe we can run Windows OS, Linix OS on Motorola as well as Intel or AMD or some other processors.

but how the same compiler is able to generate code for different processor.

thanks in advance.

the compiler generates a machine code which is dependant on the platform where the compiler is installed.

Read about how Java attained platform independance. That will give a brief idea of why C is not like that.

This Question is not programming related but rather important for all compiler related programming languages especially the Language C.

what is portabily?

since my graduation i have been taught C is not 100 % portable language.

but i dint get any satisfactory answers for,not 100 % portable?
where its lagging and why can't we make it 100 % portable?

How a compiler generates the portable code for all the processors

Assembly language is considered as non portable language because the instruction are understandable only by the specific processor.

but how a compiler is able to generate code that is understandable by all the processors.

when i install a compiler i dont worry on what processor my system runs ( i only worry about OS, what OS does to compiler?)

again the OS may run on different processors.

but how a particular comipler is able to generate code that almost works on all processors with minor or few modifications.

i believe we can run Windows OS, Linix OS on Motorola as well as Intel or AMD or some other processors.

but how the same compiler is able to generate code for different processor.

thanks in advance.

A C compiler doesn't create code that's portable, it just creates an exe in the host machine language(well this isn't entirely true, gcc can cross compile). The source code that's created by the programmer can be portable, if it uses the standard libraries, because you can take this source(plus standard libraries) to another machine with a C compiler and compile it and it should work without change...

Edited 7 Years Ago by gerard4143: n/a

A C compiler doesn't create code that's portable, it just creates an exe in the host machine language(well this isn't entirely true, gcc can cross compile). The source code that's created by the programmer can be portable, if it uses the standard libraries, because you can take this source(plus standard libraries) to another machine with a C compiler and compile it and it should work without change...

so its the source code that is portable not the exe/a.out code.

so if i write a c code by using standard library functions the code generated( assembly or object to be specific) for a processor will depend on the OS, where as the interface like printf or scanf is same, but code generated is different for different systems.

still i dint get the clear relation/distinction between the
Compiler -> OS ->Processor in stage wise .

the compiler generates a machine code which is dependant on the platform where the compiler is installed.

Read about how Java attained platform independance. That will give a brief idea of why C is not like that.

is the java 100% poratble?

i dont have idea of java.

can you document few details/ differences about java and c with respect to compilation , code generation and portability.

thanks in advance.

is the java 100% poratble?

i dont have idea of java.

can you document few details/ differences about java and c with respect to compilation , code generation and portability.

thanks in advance.

Java has something called a JVM (Java Virtual Machine).
A java compiler compiles and generates target code for the JVM. (Google about JVM). The same JVM is used in different machines.
Java has an interpreter which takes the target instructions (made for JVM) and executes them according to the host machine specification. The interpreter is smart enough to handle the execution.
Just google about compiler design and its portability.

This article has been dead for over six months. Start a new discussion instead.