Reputation: 7048
If I write in C or C++ on for example: Windows. Is it guaranteed than I can compile and run it on any other operating system such as Mac OS, Linux, Unix-like systems? So, does it mean C or C++ is cross-platform language?
Upvotes: 5
Views: 12379
Reputation: 11493
For Mac OSX, Linux, and, of course, Windows, you can write and compile C++. From personal experience, I've always found Windows to be easiest for C++ usage, closely followed by Linux, and with Max OSX trailing distantly behind. The compilers tend to be temperamental in my experience, and either because the support community is better for C++ on Windows, or because it's naturally better for programming, I've always had less problems with Windows. Though I labeled it in second place, I don't have that much experience in Linux.
Edit: You say "guaranteed" to run and compile. For basic C++ this is definitely the case, but some more advanced features may have varying support across platforms.
Upvotes: -1
Reputation: 31952
If you directly access any Windows API, it will fail to run (or even compile) on other platforms. If you use a standard function which indirectly accesses the correct API, or if you add #ifdef guards and access the correct platforms API, then the answer is better. The former should be cross platform. Latter will work on platforms your code caters to.
Upvotes: 2
Reputation: 44298
No.... there are C and C++ compilers for many many many platforms, but different compilers have their own quirks, and the libraries they link to are completely different on various platforms. Mozilla had a guideline of what features to use and what to avoid to make your software cross platform.
There are environments like cygwin that help with cross platform compatibility in windows *nix.
You can write libraries that are stock standard C that don't have dependencies on platform libraries that will be pretty portable
Upvotes: 4
Reputation: 182769
If you write a C or C++ program that strictly complies with some standard, then the program should work on any platform that supplies a tool chain that complies with that standard. In that sense, C and C++ are cross-platform languages.
Upvotes: 16