Thread: C - Portable?

  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
    28,413
    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).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 09: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, 07:58 AM
  5. Portable nonbusy hold?
    By Imperito in forum C Programming
    Replies: 2
    Last Post: 09-06-2002, 11:48 AM