Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a cross-platform program?

I searched for some literature about cross-platform programing development and I didn't find something really good.

I'm not looking for a Virtual Machine for cross-platforming like Java does.

Is there any book or literature about this?

like image 438
rigon Avatar asked Jul 10 '10 00:07

rigon


1 Answers

I'd say that this boils down to:

  • Not using non-standard "standard library" features, where non-standard depends on what platforms you target (e.g. POSIX-compatible systems). For example, if you use C don't use popen() if you want your application to run on non-POSIX systems.
  • Make sure you handle endianess correctly where it needs to be, e.g. when you transmit data over the network to another computer possibly using a different byte order.
  • Write only compliant code, e.g. don't depend on GCC/VC/name-your-compiler specific features.

On a more practical level my advice is:

  • Use cross platform libraries that abstract the non-standard functionality you need, or write your code to handle all the platforms that you target.
  • And, related to the point above, stay away from non-cross platform dependencies. E.g. use OpenGL instead of Direct3D, and Qt/Gtk/whatever instead of your platforms native widget toolkit.

EDIT: There's more stuff to think about, like not assuming that / is used as the path separator, or making invalid assumptions about which characters are allowed in file names.

like image 144
Staffan Avatar answered Oct 09 '22 09:10

Staffan