aspose file tools*
The moose likes C / C++ and the fly likes Platform dependency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "Platform dependency" Watch "Platform dependency" New topic
Author

Platform dependency

Santosh Kumar Nekkanti
Greenhorn

Joined: Feb 17, 2011
Posts: 8

Hi all,
I learnt that C language is platform dependent ,so the code which behaves correctly for one OS, will not work for other OS.(1)Am I write?(2)What features of a software language depend on the OS?

Regards,
Santosh Kumar N.
Santosh Kumar Nekkanti
Greenhorn

Joined: Feb 17, 2011
Posts: 8

Hi ,

Please answer the question so that I can proceed further.Please do this favour.

Regards,
Santosh Kumar N.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Not certain; I was hoping somebody else would give you an answer. The C code tends to be the same on different platforms, but the compiler is very different because different platforms (and even more so, different types of chip) require different binary code. There are lots of differences between OSs, but these are a few of the best-known.
  • Line end: \n on *nix and newer Macs, \r on old Macs (very unusual nowadays) and \r\n on DOS/Windows
  • File separators: \ on DOS/Windows and / on Mac and *nix.
  • Path Separators: ; on DOS/Windows and : on Mac/*nix.
  • End-of-file: ctrl-D (and maybe something else) on *nix/Mac, ctrl-Z on DOS/Windows.
  • There are lots of other minor differences. Many applications can compensate for different line ends, etc., but not all.
    Jesper de Jong
    Java Cowboy
    Saloon Keeper

    Joined: Aug 16, 2005
    Posts: 13870
        
      10

    When you compile C or C++ code, you usually compile it directly to native machine code and link it with libraries that are specific to the operating system. So if you compile your C program on Windows, you will get an *.exe file with Intel x86 machine instructions in it, and containing calls to Windows operating system functions. You cannot run that program on a different operating system or on a system which doesn't have an Intel x86 CPU.

    Contrast that to Java: you compile Java to bytecode, which runs on the JVM. The bytecode can run on any computer or other device where there is a JVM, it doesn't matter what kind of CPU the device has. Also, all the classes and interfaces in the standard Java library are guaranteed to be available.

    Note that in principle you could compile C or C++ to bytecode too. There's nothing inherent in the programming languages that makes them necessarily platform-dependent. It's just how C and C++ are commonly used. C and C++ have a number of features that make them efficient languages, but also harder to make programs that compile on different machines and operating systems. For example, the size of an int in C and C++ depends on your compiler and target CPU and operating system. On some systems, an int is 32 bits, on other systems it's 64 bits and on other systems it might be only 16 bits. (In Java, an int is always 32 bits, no matter what CPU the program is going to be running on).

    Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
    Scala Notes - My blog about Scala
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Platform dependency
     
    Similar Threads
    java thread?
    I18N DIALOG PRINT
    java operating systems
    why java is called
    Dynamic Language Support in Java 7