answersLogoWhite

0


Best Answer

Platform-Independent code, is a code that can run on any Operating System. So to write Platform-Independent codes, don't use codes that can work ONLY in the OS you program it in. w4r3_w01f at live dot com

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write platform independent C code?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is compiler is platform independent?

No. (Of course you should specify what compiler you are talking about.)


Is c platform independent or dependent?

No. Not only will C source code have to be recompiled to work on different machines, but implementations of platform-specific concepts (file system management, UI, etc.) will have to be rewritten completely to work on a new machine.


Why is c language said to be portable?

Well, C is not platform dependent. You can compile C into source code on a Windows, Mac, Unix or any other operating system as long as you are using that type of computer. You could write code that can be compiled on almost any operating system. But the programs you write may or may not be able to move from system to system based on whether or not you use tools specific to that operating system. Java is not actually platform independent either because you need JVM to run it. It's just that most computers come with JVM installed. Both of the above are wrong. The C language specification itself is platform-dependent, as there are numerous places where ambiguities (both intentional and unintentional) cause different behavior according to how both the platform AND the C-compiler writer chose to behave. Thus, while it is possible to write a C program which is highly-portable, that program is still dependent on the exact implementation of the C compiler and OS it runs on. So, the behavior of a C program depends on the platform. The Java Language is platform INDEPENDENT, since it does NOT have the implementation ambiguities of C, and has a completely-standardized interface to all platforms (the JVM spec). Naturally, the JVM program is plaform dependent, as creating it to conform to the Java VM specification requires knowledge of the peculiarities of the platform.


Is platform independent feature means java can be run on windows XP and windows 7 but c or c plus plus does not?

No. The term platform independence in Java does not mean that any other programming language cannot be run in multiple OS platforms. Actually platform independence means that the java code can be run in multiple platforms with little or no customization. The code that can execute in a Windows platform can run as it is in a Linux box, whereas other programming languages need to be customized based on the platform they will be implemented in.


Why c is machine independent language?

C source code is portable; it can be compiled upon any machine with a suitable C compiler in order to produce the machine-dependant code (the machine code). However, C can also be used to write machine-dependant code, or code that is dependant upon specific platforms. In order to be completely portable, the code must use the C standard library and/or generic libraries.

Related questions

Is compiler is platform independent?

No. (Of course you should specify what compiler you are talking about.)


Is c platform independent or dependent?

No. Not only will C source code have to be recompiled to work on different machines, but implementations of platform-specific concepts (file system management, UI, etc.) will have to be rewritten completely to work on a new machine.


Is cloud computing is platform dependent or independent?

c is platform dependent


Why java is platform independent and also prove how it is possible?

WHY MEANS the java is a platform independent language for the sake of it has its own platform to run the program it doesn't require any platforms like c and C++


Is c plus plus platform dependent or platform independent?

The language itself is platform independent. However, specific implementations may be platform dependant. For instance, code written with Microsoft Visual C++ is generally intended to be compiled upon Windows platforms only, not Linux or Mac platforms. Although pre-compiler directives can filter machine specific code to suit the current platform, programmers need to be careful to avoid implementation-specifics when porting code to other compilers. If code is intended to be portable, it's better to use an implementation that conforms to the ISO standard, and that has implementations for all the intended platforms to accommodate platform-specific code.


Why c is platform dependant?

Well, C is not platform dependent. You can compile C into source code on a Windows, Mac, Unix or any other operating system as long as you are using that type of computer. You could write code that can be compiled on almost any operating system. But the programs you write may or may not be able to move from system to system based on whether or not you use tools specific to that operating system. Java is not actually platform independent either because you need JVM to run it. It's just that most computers come with JVM installed. Both of the above are wrong. The C language specification itself is platform-dependent, as there are numerous places where ambiguities (both intentional and unintentional) cause different behavior according to how both the platform AND the C-compiler writer chose to behave. Thus, while it is possible to write a C program which is highly-portable, that program is still dependent on the exact implementation of the C compiler and OS it runs on. So, the behavior of a C program depends on the platform. The Java Language is platform INDEPENDENT, since it does NOT have the implementation ambiguities of C, and has a completely-standardized interface to all platforms (the JVM spec). Naturally, the JVM program is plaform dependent, as creating it to conform to the Java VM specification requires knowledge of the peculiarities of the platform.


Is Visual C or Visual C plus plus platform independent?

No, M$ Windoze only.


How to write a code in c plus plus for 3D animation project?

C++ has no generic graphics methods whatsoever. All graphics are platform-specific and therefore require a suitable API and library to support your specific platform and hardware. Thus there is no generic C++ code for 2D animation let alone 3D animation.


Is c plus plus platform independent?

Yes. Code must still be written specifically to suit each platform, however C++ itself is not platform dependant. To port code between platforms, the source code needs to employ compiler directives (#ifdef/#ifndef) to filter the required code to suit the current platform, and the code must be compiled separately upon each platform. By contrast, Java need only be compiled once on any platform, and the resultant byte code can then be interpreted and executed upon any machine that supports a Java Virtual Machine implementation. This makes it much easier to produce cross platform applications, but performance will suffer as a result of the interpretation.


Why is c language said to be portable?

Well, C is not platform dependent. You can compile C into source code on a Windows, Mac, Unix or any other operating system as long as you are using that type of computer. You could write code that can be compiled on almost any operating system. But the programs you write may or may not be able to move from system to system based on whether or not you use tools specific to that operating system. Java is not actually platform independent either because you need JVM to run it. It's just that most computers come with JVM installed. Both of the above are wrong. The C language specification itself is platform-dependent, as there are numerous places where ambiguities (both intentional and unintentional) cause different behavior according to how both the platform AND the C-compiler writer chose to behave. Thus, while it is possible to write a C program which is highly-portable, that program is still dependent on the exact implementation of the C compiler and OS it runs on. So, the behavior of a C program depends on the platform. The Java Language is platform INDEPENDENT, since it does NOT have the implementation ambiguities of C, and has a completely-standardized interface to all platforms (the JVM spec). Naturally, the JVM program is plaform dependent, as creating it to conform to the Java VM specification requires knowledge of the peculiarities of the platform.


How do you write an Algorithm for a C plus plus Program?

You don't write an algorithm for a C++ program, unless you are documenting the C++ program after-the-fact. The normal procedure is to write the algorithm first, in a language independent fashion, and then translate that stated algorithm into C++ code, or into whatever language you wish.


Why are c and c plus plus not platform independent?

They are! You can easily write programs that will compile and run on any platform. These will mostly be trivial and will require a bit of effort on the part of the programmer, but it can be done. Compiler directives can be used to filter platform-specific calls, thus the same code can produce code that is specific to any platform. However, non-trivial programs would require an in-ordinate amount of effort, so most software is initially written to support a specific platform -- generally the one that is expected to generate the greatest profit. The design of the software is generally such that cross-platform versions can be ported relatively quickly after initial release (depending on the complexity). But this is not a limitation of C/C++, nor is it the fault of the various platform designers -- it is simply a matter of economics. There's no point writing a program for a platform relatively few people will actually use, you write for the most popular, or the one that best serves your needs (XBOX or PS3 for games software, for instance).