Thread: is it true that .exe file will run only on windows platform ??

  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72

    is it true that .exe file will run only on windows platform ??

    when we compile a C program.. we get a .exe file which is use to execute the program. Then Is it true that this .exe file will run only on windows platform.??
    Because I heard that .exe file contains MACHINE CODE. So I don't think platform should matter. But I also heard that C language is Platform Dependent.
    Someone please Help me out.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You're correct, it is OS dependent.

    BUT, C code can be re-compiled for any Operating System on the planet (and beyond!), and then be run on that system.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    C code is platform independant, the generated executable is surely platform dependant. But i think i've heard of an OS that supported Windows executables, i don't remember which.
    Devoted my life to programming...

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    What do you mean by ".exe file?" A program file which is stored using PE file format? Or, more specifically, a Windows program? The .exe format itself isn't Windows-specific.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    What else is it used for?
    Devoted my life to programming...

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well if it's Turbid-C, I suppose you could slide the floppy disks under a wobbly table leg or something.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You can also run Windows executables under Wine on Linux, but to run them on other platforms requires an emulator such a VirtualPC VirtualBox, VMWare...
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    .exe doesn't mean "Windows". DOS used .exe files also. Probably before your time, but the point remains.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Gaurav Singh View Post
    when we compile a C program.. we get a .exe file which is use to execute the program. Then Is it true that this .exe file will run only on windows platform.??
    Yes. It is a windows specific executable file. By itself it will not run anywhere else.
    Similarly you're not going to run a linux or a mac program on windows.

    Yes they all contain machine code, but that code makes calls into the Operating System and those calls are different on each OS... For example, the printf() function in the windows libraries is going to be totally unlike the printf() function in the Mac or Linux libraries.

    The "C is multiplatform" is true only at the *source code* level and then, only because of standards like C99 that define a standard set of library functions for all platforms.

    That said... there are programs called "Emulators" that can run Windows programs on other platforms... eg. Wine for Linux which lets you run some (but not all) windows programs under Linux. This is a program running your program, not your program running natively on another OS.

  10. #10
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by quzah View Post
    .exe doesn't mean "Windows". DOS used .exe files also. Probably before your time, but the point remains.


    Quzah.
    Although, the two things aren't really the same. A modern .exe file has a DOS exe header which points to a PE header -- it's the PE header that actually tells Windows what to do when it loads the executable. If such an exe is executed on DOS, which doesn't understand the PE format, it runs a little stub program that prints the message "This program cannot be run in DOS mode."

    Yes, every .exe file has a little DOS program built into its header just to print that error message. Ick
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  11. #11
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Gaurav Singh View Post
    when we compile a C program.. we get a .exe file which is use to execute the program. Then Is it true that this .exe file will run only on windows platform.?? Because I heard that .exe file contains MACHINE CODE.
    That is not precisely true. All executable files generally rely on some functionality provided by the host system (combination of hardware, operating system, etc). Some operating systems recognise particular executable formats.

    The picture is blurred a little by emulators and virtual machines: for example, there are emulator environments that can be installed on unix systems that can support running executables targeted for windows systems.

    Quote Originally Posted by Gaurav Singh View Post
    So I don't think platform should matter.
    That is only true in lands of fantasy.

    Real software cannot run by itself - it requires some host system with physical properties (hardware) in order to run. Which means the hardware platform always matters, as does the software platform (eg operating system) that acts as an intermediary between applications and hardware.

    In future, the nature of hardware and operating system platforms may change, but it will never be possible for software to just execute with no platform whatsoever.

    Quote Originally Posted by Gaurav Singh View Post
    But I also heard that C language is Platform Dependent.
    That is not true. The C language itself is platform independent, because the C standard only specifies a minimum set of language and library features that can be implemented across all possible target systems.

    The executable form that C code is translated to is platform dependent though. It is also possible to write C code that accesses platform-specific features (for example, C code that uses win32 API functions is specific to windows platforms).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  12. #12
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Most C code is portable, which means it can be compiled on every operating system. The output machine code (the .exe file) is platform-dependent. If an executable file ends in ".exe", then it's most likely machine code for Windows or MS-DOS. Unix operating systems, like Linux, BSD, and OS X, can run Windows or MS-DOS binaries with Wine.

  13. #13
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by brewbuck View Post
    Yes, every .exe file has a little DOS program built into its header just to print that error message. Ick
    "In every Windows program, there's a little DOS program struggling to get out."
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by CommonTater View Post
    Yes. It is a windows specific executable file. By itself it will not run anywhere else.
    Similarly you're not going to run a linux or a mac program on windows.

    ...

    That said... there are programs called "Emulators" that can run Windows programs on other platforms... eg. Wine for Linux which lets you run some (but not all) windows programs under Linux. This is a program running your program, not your program running natively on another OS.
    An OS is just a "program running your program".


    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    Quote Originally Posted by quzah View Post
    An OS is just a "program running your program".
    Hehe, you asked for it! And who runs the OS?
    Last edited by GReaper; 02-06-2011 at 10:15 AM.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  3. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM