There is no silver bullet at the tongue level. The best you can do is stick to your locale as close as possible. Most compilers have options for issuing warnings or errors if you use an extension specific to a particular compiler (with Visual C ++, /Za will disable non-standard language extensions). But this is not ideal, since no compiler implements absolutely 100% of the standard, so you can still have portability problems even with strictly compatible code.
Also keep in mind that a lot of everyday code really takes advantage of the extensions, or undefined - or the behavior defined by the compiler, often without implementing it, so it would be impractical to compile it in completely standard mode.
You should also know that standards allow you to be different. For example, types such as int can be of different sizes for different systems. Windows is LLP64, while most Unix-based OSs are LP64.
At the system level, I donβt know the ideal way to make sure that the programmer does not rely on something specific to the system (for example, <windows.h> or <pthreads.h> ).
Itβs best to do everything so that developers can run test builds on all target platforms.
Adrian mccarthy
source share