Resources for Cross-Platform C / C ++ Development

What resources exist for writing C / C ++ code that runs on multiple platforms and compilers? For example, I regularly ask questions such as:

  • What preprocessor macros are automatically detected in different compilers and environments? (e.g. __GCC__ , WIN32 , __WIN32__ , __CYGWIN__ )
  • Which versions of compilers and standard libraries support relatively new "standard" functions (for example, long double trigonometric functions C99 sinl (), cosl (), ...)
  • What functions are available on different platforms to perform typical tasks when there is no single portable function? (for example, obtaining the current time accurate to the second second)

I often write code that should compile for Linux / gcc, cygwin, mingw32 and Visual Studio, and I often have to compare notes from several sources (Linux man pages, MSDN, compiler documents) to get the information I need. This should be a problem that developers face all the time - are there any resources that compile this information into an easily digestible link?

(For this question, I am not particularly interested in cross-platform libraries such as wxWidgets or boost. I am more interested in resources or methods that will help someone write their cross-platform library or program.)

EDIT: This is an example of the type of page I'm looking for: http://predef.sourceforge.net/precomp.html . A good overview of the various compilers / environments and preprocessor macros that can be used to identify them. It would be great to find a similar resource that compared almost equivalent functions on different platforms (for example, gmtime_r () or ftime () on Linux vs _gmtime_s () or _ftime () on Windows) when there is no common function.

+6
c ++ c portability
source share
4 answers

Here is one resource you might find useful Predefined C / C ++ Compiler Macros

+3
source share

The main way to write cross-platform code is to write code that is platform-independent. For example, almost all UNIX source utilities can be written without reference to a specific platform. Writing code that depends on specific macros using conditional compilation is not best practice.

+1
source share

It really depends on your specific project, but I will try

  • adhere to ISO-compliant code and POSIX, if possible;
  • use -Wall and clear all warnings;
  • check autoconf and autotoolset to see if they can help.
+1
source share
0
source share

All Articles