![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 10
Rep Power: 0
![]() |
A stupid compiler question.
As I understand it, compilers generally generate code in the following manner: source code>object file(s)(which might be linked)>final executable in machine code.
Now, providing that a source file is compiled for a certain CPU architecture (eg, x86) why shouldn't a file compiled on Windows work on a Linux system, and vise versa? |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
No problem if your code is completely portable; however, you won't be able to do much if you need to get at the hardware (keyboard, display, etc.), as different OSs have differently written drivers and interfaces that you are dealing with if you use the implementation specific libraries..
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
You may be using platform dependent libraries, APIs, objects, etc. For instance, you can't run code that references windows.h on a Linux machine.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 4
![]() |
As correctly stated by the other two posts, I second that.
Also, just notice, while generating the executable machine code, C/C++ compilers wud basically generate an .exe file and as you know very well, .exe files can only be run in windows. (Wine is something different in this case) Also, the same in Linux wud be some .o file to a "a.out" file providing the output. In short, the executable made has code that can be understood by that particular operating system. However, Java becomes the master of all ...becoz, it generates a class file on executing it and that only needs an interpreter on the machine it is running... Happy programming....!!!
__________________
Visit: http://www.somaiya.edu |
|
|
|
|
|
#5 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|