Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write portable code in c++?

What are the things that I should keep in mind to write portable code? Since I'm a c++ beginner, I want to practice it since beginning.

Thanks.

like image 520
understack Avatar asked Jun 23 '10 16:06

understack


People also ask

What is portable C code?

The Portable C Compiler (also known as pcc or sometimes pccm - portable C compiler machine) is an early compiler for the C programming language written by Stephen C.

Is C C++ portable?

C++ is ultra portable and has compilers available on more platforms than you can shake a stick at. Languages like Java are typically touted as being massively cross platform, ironically they are in fact usually implemented in C++, or C. That covers "portability".

Is C portable or not?

C is not portable because not only is it tied to a specific OS in many cases, it is also always tied to a specific hardware architecture once it has been compiled.

Which is portable integer type in C?

The most obvious problem with writing portable C is that the size of various types changes between platforms. C defines five integer types, in signed and unsigned variants: char, short, int, long, and long long. On the system where I first learned C, these were 8, 16, 16, 32, and nonexistent, respectively.


1 Answers

  • learn to use the standard library
  • read books (eg. this one)
  • when you're experienced, learn to use boost
like image 89
Alexandre C. Avatar answered Sep 23 '22 06:09

Alexandre C.