• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Platform dependency

 
Greenhorn
Posts: 8
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

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

Regards,
Santosh Kumar N.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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).
     
    Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic