Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 29th, 2005, 4:14 PM   #1
conbrio
Newbie
 
Join Date: Apr 2005
Posts: 10
Rep Power: 0 conbrio is on a distinguished road
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?
conbrio is offline   Reply With Quote
Old Jun 29th, 2005, 5:37 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Jun 30th, 2005, 11:16 AM   #3
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,475
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Jun 30th, 2005, 11:59 AM   #4
java_roshan
Professional Programmer
 
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 4 java_roshan is on a distinguished road
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
java_roshan is offline   Reply With Quote
Old Jun 30th, 2005, 1:34 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
C/C++ compilers wud basically generate an .exe file and as you know very well, .exe files can only be run in windows
This may be misleading. Compilers (the linker/locator associated with them, actually) generally use an extension compatible with the platform they're designed to support, as you mention regarding the .out extension.
__________________
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC