Skip to content

Portability Gotchas

Ryan Pavlik edited this page Mar 3, 2015 · 1 revision

VRPN builds and runs on a wide array of platforms and compilers. Here are some "gotchas" you might want to be aware of if you're writing code to go in VRPN.

Developed on Visual Studio, now building elsewhere...

  • In general, Visual Studio implicitly includes more headers than other compilers, so if it builds in VS, it still may be missing headers. Include what you use.
  • defined(_WIN32) is the correct check to put around code that only makes sense on Windows.
  • defined(_MSC_VER) is the correct define to check if we're building with Visual Studio.
    • Corollary: defined(_WIN32) does not imply defined(_MSC_VER) - there are other compilers and cross-compilers.

Developed in modern tools...

  • snprintf is not available in older Visual Studio versions (2008?) so can't be used at the time being. TODO: Figure out a suitable solution.

Developed on a desktop...

  • Byte order varies between machines. Always use the hton/ntoh functions VRPN provides if you're putting data on the network on your own.
  • On a related note, though USB data is often little-endian just like your desktop, that doesn't mean memcpy works everywhere to load USB data. Use vrpn_unbuffer_from_little_endian

Developed on a POSIX (*nix/Mac OS X) system...

  • M_PI isn't in the C++ or C standard. It's a POSIX thing. TODO: Figure out what the solution is, without involving defining M_PI in lots of source files.