Portable C ++ code means that such code can be compiled for (almost) any platform and any implementation. Thus, goals are not important if the program should work on
- various operating systems (windows, linux, OSX)
- different architectures (x86, x86-64, titanium, sparc, arm)
- different runtime libraries / compilers (gcc, clang, MSVC)
To achieve this, you have to take into account many aspects - Do not use the API and behavior defined during implementation, use only the standard library - Do not use architectures, certain assumptions and behavior, for example, that char has 8 bits, or negative integers are 2-complement and overflow, or that int is 32 bits long, etc.
The problem is that you often have to use material for which there is no standard in C ++, for example, network interfaces. Therefore, libraries often try to work around this problem by using various specific solutions for the most popular systems selected by the preprocessor.
So, as you see, portability must always be seen in context, because absolute mobility is not practicable. For example, C ++ code portable for any compiler compatible with C ++ 11 (but most compilers are not 100%, see MSVC 12/2013) or portable for compilers compatible with C ++ 11 and POSIX (so thatβs all Unix systems can use this). And so on.
Superlokkus
source share