C - Portable?

This is a discussion on C - Portable? within the C Programming forums, part of the General Programming Boards category; referring to ANSI C book by K and R "With a little care it is easy to write portable programs, ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    99

    C - Portable?

    referring to ANSI C book by K and R

    "With a little care it is easy to write portable programs, The standard makes portability issues explicit"

    I expects, he hints me, that the C language <without the standard library> , is portable and, if I dont use the std. library, my program is guarenteed to run over any system.

    but how can I write a program without the std. library, when even writing a simple Hello World program requires stdio.h library?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,980
    I expects, he hints me, that the C language <without the standard library> , is portable and, if I dont use the std. library, my program is guarenteed to run over any system.
    What exactly is the part that hints that? It seems to me that what you quoted means that it is possible to write portable C prograns that use the standard library (since that is part of the standard), as long as you are careful not to use it in a nonportable way (e.g., relying on system() calls).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    If your program only uses the standard library, then it will be portable.

    > but how can I write a program without the std. library
    This normally happens when you start writing programs for free-standing implementations (also know as an embedded system). Say for example you have a micro processor attached to a particular kind of LCD display.

    Your program writes "hello world" to the LCD, via some LCD library (possibly written by you). If in the future you want to use another kind of LCD display, then you might need another library (or you might need to write it yourself).

    It's more a case of you don't need a std library in order to be able to write code for the machine in question. However, all free-standing code is inherently non-portable.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-14-2009, 02:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 08:38 AM
  3. Replies: 3
    Last Post: 09-01-2005, 11:47 AM
  4. which Portable mp3 player?
    By Raihana in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 01-09-2004, 06:58 AM
  5. Portable nonbusy hold?
    By Imperito in forum C Programming
    Replies: 2
    Last Post: 09-06-2002, 11:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21