Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing cross-platform apps in C

What things should be kept most in mind when writing cross-platform applications in C? Targeted platforms: 32-bit Intel based PC, Mac, and Linux. I'm especially looking for the type of versatility that Jungle Disk has in their USB desktop edition ( http://www.jungledisk.com/desktop/download.aspx )

What are tips and "gotchas" for this type of development?

like image 273
Dinah Avatar asked Aug 30 '08 05:08

Dinah


People also ask

Are C programs cross-platform?

The language C itself is cross-platform, because you don't directly run C code on machines. The C source code is compiled to assembly, and assembly is the platform specific code. The only non cross-platform part are the compilers and the resulting assembly.

Can you make cross-platform apps in C++?

You can build native C++ apps for iOS, Android, and Windows devices by using the cross-platform tools available in Visual Studio. Mobile development with C++ is a workload available in the Visual Studio installer.

Are C++ apps cross-platform?

C++ is also one of the initial cross-platform languages, even though it couldn't shift into the world of the web and mobile. C++ is best suited for developing software like operating systems, database engines, game engines, compilers, and servers. At the same time, C++ is a great choice as a cross-platform language.


1 Answers

I maintained for a number of years an ANSI C networking library that was ported to close to 30 different OS's and compilers. The library didn't have any GUI components, which made it easier. We ended up abstracting out into dedicated source files any routine that was not consistent across platforms, and used #defines where appropriate in those source files. This kept the code that was adjusted per platform isolated away from the main business logic of the library. We also made extensive use of typedefs and our own dedicated types so that we could easily change them per platform if needed. This made the port to 64-bit platforms fairly easy.

If you are looking to have GUI components, I would suggest looking at GUI toolkits such as WxWindows or Qt (which are both C++ libraries).

like image 117
Steve Wranovsky Avatar answered Oct 02 '22 04:10

Steve Wranovsky