Ad Code

Why Code portability is so important? Give out 3 ways / Guide lines to improve the code portability with examples

Why Code portability is so important? Give out 3 ways / Guide lines to improve the code portability with examples


Many applications need to be ported on to many different platforms. As we have seen, it is pretty hard to write error free, efficient, and maintainable software. So, if a major rework is required to port a program written for one environment to another, it will be probably not come at a low cost. So, we ought to find ways and means by which we can port applications to other platforms with minimum effort. The key to this lies in how we write our program. If we are careful during writing code, we can make it portable. On the other hand if we write code without portability in mind, we may end-up with a code that is extremely hard to port to other environment. Following is brief guideline that can help you in writing portable code.

Stick to the standard 
1. Use ANSI/ISO standard C++
2. Instead of using vendor specific language extensions, use STL as much as possible.

Program in the mainstream 
Although C++ standard does not require function prototypes, one should always write them.
double sqrt(); // old style acceptable by ANSI C
double sqrt(double); // ANSI – the right approach Size of data types

Sizes of data types 
cause major portability issues as they vary from one machine to the other so one should be careful with them.

int i, j, k;
… j = 20000;
k = 30000;
i = j + k;
 // works if int is 4 bytes
// what will happen if int is 2 bytes?
Reactions

Post a Comment

0 Comments