Thread: what does portability mean?

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595

    what does portability mean?

    Here's a simple question that I haven't seen bandied about, but can't say I review this board much, so I apologize if I am in error on that.

    What does the phrase, cross platform portability, mean? Does it mean if I compile a program using only standard C++ it will run on Windows and Apple and Unix platforms or it will compile on all three platforms? I mean if I write a program with non-standard code and the exe (or whatever) file runs on all three platforms, does it really matter if it compiles on all three platforms or not?

    Maybe the answer is---depends. If you are a hobbyist (like me) and don't care about code maintenance issues, or if you don't care about compatability with other platforms, then it's probably not a big deal. But if you are a professional programmer and code maintenance is an issue or if you are looking for the broadest possible market for your product, then portability is a potentially big issue.

  2. #2
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Basically portability means that you can run your programs on many systems. There's a standard (usually ANSI) that all (or most) OSes adhere to as far as understanding code. As long as you stay within those standards, you programs should work fine... however C++ is a lot more tricky to do this with than maybe just C.
    EntropySink. You know you have to click it.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Portable programs can be moved to another platform and compiled without changes or with minimal changes.
    Maybe the answer is---depends. If you are a hobbyist (like me) and don't care about code maintenance issues, or if you don't care about compatability with other platforms, then it's probably not a big deal. But if you are a professional programmer and code maintenance is an issue or if you are looking for the broadest possible market for your product, then portability is a potentially big issue.
    This is a naive view, but still correct to some extent. I see portability as a measure of quality. If you don't need to use non-portable features of a platform then a portable program should be written for the sake of good style. If you do need to use non-portable features, you should modularize them sufficiently so that porting the program to another platform is relatively painless. For example, the following program is not portable and if it were huge would be a pain to modify:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main ( void )
    {
      /* Do stuff */
    
      system ( "cls" );
    
      /* Do more stuff */
    
      return 0;
    }
    The problem is that using "cls" as the argument to system will break on platforms that do not use cls as a clear screen command. If system ( "cls" ) were called hundreds of times then porting this program would be...well, put bluntly it would be a real *****. It could be better written like this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void clear ( void )
    {
      system ( "cls" );
    }
    
    int main ( void )
    {
      /* Do stuff */
    
     clear();
    
      /* Do more stuff */
    
      return 0;
    }
    The non-portable feature is still there, but the effort it takes to change that feature to suit a new platform is as simple as changing "cls" to "clear" or some other command.

    So basically, the measure of portability for a program, or modularization to ease portability, is a good measure of program quality. Program quality is something every programmer should strive for, the end result should be portable simply because you as the programmer care about quality, even if portability isn't a concern for you.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > even if portability isn't a concern for you
    ..it might be for someone else.
    (Open-source)
    The world is waiting. I must leave you now.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Thanks.

    The answers confirm my suspicion that the concept is murky. At least when two respectable programmers disagree, (one says runs, the other says compiles), then in my mind the concept isn't cut an dried.

    Or maybe it means that run and compiles are one and the same????

  6. #6
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    No... it is 'compiles' and not 'runs'.

    A program that is compiled on a windows machine will not run on linux (usually) and vice versa. But a portable program should be able to be compiled on either with little to no changes and then run.

    "Program quality is something every programmer should strive for, the end result should be portable simply because you as the programmer care about quality, even if portability isn't a concern for you."

    And that has to be really close to the coolest programming statement I have ever heard.
    Last edited by Betazep; 10-02-2002 at 03:05 PM.
    Blue

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> the concept is murky

    Not murky. Truly portable code should compile on other systems. The object produced by a compiler cannot be expected to run on different hardware - the processor opcodes for example, would not be the same.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. COM application portability
    By Opariti in forum Windows Programming
    Replies: 3
    Last Post: 11-21-2008, 01:17 PM
  2. Portability
    By rwmarsh in forum C++ Programming
    Replies: 2
    Last Post: 07-04-2006, 10:36 PM
  3. Replies: 1
    Last Post: 10-24-2005, 06:35 AM
  4. Program Portability (code portability)
    By Perica in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2002, 10:03 AM
  5. portability of a pause function
    By Eigenvalue in forum C Programming
    Replies: 2
    Last Post: 09-15-2002, 02:22 PM