Can I run C and C ++ on any platform?

If I write in C or C ++, for example: Windows. Is this a guarantee than I can compile and run it on any other operating system, such as Mac OS, Linux, Unix-like systems? So, does C or C ++ mean a cross-platform language?

+4
source share
4 answers

If you are writing a program in C or C ++ that strictly follows some standard, the program should work on any platform that supplies a tool chain that complies with this standard. In this sense, C and C ++ are cross-platform languages.

+16
source

No. There are C and C ++ compilers for many many platforms, but different compilers have their own quirks, and the libraries to which they refer are completely different on different platforms. Mozilla indicated which features to use and what should not be done to turn your software into a cross-platform.

There are environments such as cygwin that help with cross-platform compatibility on Windows * nix.

You can write libraries that are standards in the C warehouse, which have no dependencies on the platform libraries, which will be quite portable.

+4
source

If you directly access any Windows API, it will not work (or even compile) on other platforms . If you use a standard function that indirectly accesses the correct API or adds #ifdef guard and accesses the correct platform API, then the answer is better . The first should be cross-platform. The latter will work on the platforms that your code suits.

+2
source

For Mac OSX, Linux, and, of course, Windows, you can write and compile C ++. From personal experience, I have always believed that Windows is easiest to use for use in C ++, followed by Linux, and Max OSX is behind. Compilers tend to be temperamental in my experience, and either because the support community is better for C ++ on Windows, or because it is naturally better for programming, I always had less problems with Windows. Although I named it in second place, I don't have much experience on Linux.

Edit: you say โ€œguaranteedโ€ to run and compile. For basic C ++, this is definitely the case, but some more advanced features may have different support on different platforms.

-1
source

All Articles