C examples...?

Discussion in 'C Programming' started by jwl, Dec 25, 2004.

  1. jwl

    jwl Guest

    Hi everyone

    I learn best by example so I'd like to find C source code to study,
    especially stuff showing how to use the standard library. The trouble is,
    although I can find tons of non-standard code, I can't find any strictly
    ISO C code. Does anyone know a link to some interesting programs in
    standard C?

    Thanks for your time
    jwl
     
    jwl, Dec 25, 2004
    #1
    1. Advertising

  2. jwl

    Giovanni Guest

    jwl wrote:
    > Hi everyone
    >
    > I learn best by example so I'd like to find C source code to study,
    > especially stuff showing how to use the standard library. The trouble is,
    > although I can find tons of non-standard code, I can't find any strictly
    > ISO C code. Does anyone know a link to some interesting programs in
    > standard C?
    >
    > Thanks for your time
    > jwl


    Thou all the gurus in this NG will probably contradict me the majority
    of the code you say non-standard are standard as long as the compile
    witout errors. If you have doubts compile them wit the ansi option
    (e.g. "gcc -ansi ....") and you'll find where they fail.

    Ciao
    Giovanni
    --
    A computer is like an air conditioner,
    it stops working when you open Windows.
    Registered Linux user #337974 <http://counter.li.org/>
     
    Giovanni, Dec 25, 2004
    #2
    1. Advertising

  3. jwl

    Rich Gibbs Guest

    jwl said the following, on 12/25/04 10:31:
    > Hi everyone
    >
    > I learn best by example so I'd like to find C source code to study,
    > especially stuff showing how to use the standard library. The trouble is,
    > although I can find tons of non-standard code, I can't find any strictly
    > ISO C code. Does anyone know a link to some interesting programs in
    > standard C?
    >


    One source you might want to have a look at is P.J. Plauger's excellent
    book, _The Standard C Library_. It discusses what the standard requires
    of the library, and contains an implementation of the library, which is
    in portable C to the extent possible. Mosy important for learning, it
    contains a discussion of *why* things are done.


    --
    Rich Gibbs
     
    Rich Gibbs, Dec 25, 2004
    #3
  4. jwl

    Malcolm Guest

    "jwl" <> wrote
    >
    > I learn best by example so I'd like to find C source code to study,
    > especially stuff showing how to use the standard library. The trouble is,
    > although I can find tons of non-standard code, I can't find any strictly
    > ISO C code. Does anyone know a link to some interesting programs in
    > standard C?
    >

    Look up GNU.

    I don't think your strategy is going to be very productive, however. A lot
    of real code is difficult to read, unless it is deliberately written for the
    purpose of instructing beginners.

    Also,a large number of real world programs use some non-standard library
    calls. The facitilites provided by stdlib are very limited, for instance it
    is not possible to list files in a directory, query the state of the
    keyboard, or use any type of graphics including writing characters to set
    locations on the screen.
     
    Malcolm, Dec 25, 2004
    #4
  5. jwl

    Al Bowers Guest

    jwl wrote:
    > Hi everyone
    >
    > I learn best by example so I'd like to find C source code to study,
    > especially stuff showing how to use the standard library. The trouble is,
    > although I can find tons of non-standard code, I can't find any strictly
    > ISO C code. Does anyone know a link to some interesting programs in
    > standard C?
    >


    Take a look at the snippets collection which is online. Most of
    the code is Standard C and compatible with any os. It
    identifies the code that is os specific.

    The link:
    http://c.snippets.org/browser.php

    --
    Al Bowers
    Tampa, Fl USA
    mailto: (remove the x to send email)
    http://www.geocities.com/abowers822/
     
    Al Bowers, Dec 25, 2004
    #5
  6. On Sat, 25 Dec 2004, jwl wrote:
    >
    > I learn best by example so I'd like to find C source code to study,
    > especially stuff showing how to use the standard library. The trouble is,
    > although I can find tons of non-standard code, I can't find any strictly
    > ISO C code. Does anyone know a link to some interesting programs in
    > standard C?


    http://www.contrib.andrew.cmu.edu/~ajo/
    http://www.contrib.andrew.cmu.edu/~ajo/free-software/

    If you find anything non-standard there, that isn't marked as such, with
    the exception that I use 'is*(k)' instead of 'is*((unsigned char)k)' in
    some programs, let me know at once! ;)

    Richard Heathfield keeps a collection of C snippets, too, which
    certainly ought to be portable (right?), but I won't vouch for that.
    And I know that a lot of other clc regulars past and present have at
    least one portable C library that they like to plug off and on. So
    those might be decent starting places.

    HTH,
    -Arthur
     
    Arthur J. O'Dwyer, Dec 26, 2004
    #6
  7. jwl

    infobahn Guest

    Giovanni wrote:
    > jwl wrote:
    >
    >> Hi everyone
    >>
    >> I learn best by example so I'd like to find C source code to study,
    >> especially stuff showing how to use the standard library. The trouble is,
    >> although I can find tons of non-standard code, I can't find any strictly
    >> ISO C code. Does anyone know a link to some interesting programs in
    >> standard C?
    >>
    >> Thanks for your time
    >> jwl

    >
    >
    > Thou all the gurus in this NG will probably contradict me the majority
    > of the code you say non-standard are standard as long as the compile
    > witout errors.


    Not so. Firstly, the Standard doesn't define compiler "errors" as such.
    Instead, it talks about diagnostics. Secondly and more importantly,
    code that compiles doesn't necessarily mean code that works. Consider
    the following code:

    #include <stdio.h>

    void foo(int *m, int *n)
    {
    *m = *n++; /* Danger! */
    }

    int main(void)
    {
    int i = 42;
    foo(&i, &i);
    printf("%d\n", i); /* what does this print? */
    return 0;
    }

    is non-standard in the sense that the Standard does not define
    its behaviour, but it will typically not generate an error.


    > If you have doubts compile them wit the ansi option
    > (e.g. "gcc -ansi ....") and you'll find where they fail.


    Insufficient.
     
    infobahn, Dec 26, 2004
    #7
  8. jwl

    infobahn Guest

    jwl wrote:
    > Hi everyone
    >
    > I learn best by example so I'd like to find C source code to study,
    > especially stuff showing how to use the standard library. The trouble is,
    > although I can find tons of non-standard code, I can't find any strictly
    > ISO C code. Does anyone know a link to some interesting programs in
    > standard C?


    Search the archives for this newsgroup (I think Google is perhaps still
    just about usable); you will find plenty of sample source code not only
    presented, but also dissected and improved.
     
    infobahn, Dec 26, 2004
    #8
  9. jwl

    Chris Torek Guest

    In article <cql93h$9ig$>
    infobahn <> wrote:
    >... the Standard doesn't define compiler "errors" as such.
    >Instead, it talks about diagnostics. Secondly and more importantly,
    >code that compiles doesn't necessarily mean code that works.


    Right.

    >Consider the following code:
    >
    >#include <stdio.h>
    >
    >void foo(int *m, int *n)
    >{
    > *m = *n++; /* Danger! */


    I think you meant to write:

    *m = (*n)++;

    As it is, since the postfix "++" binds more tightly than the prefix
    "*", the expression means "increment n, and use the value it had
    before said incrementation as the operand of unary-star."

    >}
    >
    >int main(void)
    >{
    > int i = 42;
    > foo(&i, &i);
    > printf("%d\n", i); /* what does this print? */
    > return 0;
    >}
    >
    >is non-standard in the sense that the Standard does not define
    >its behaviour, but it will typically not generate an error.


    Given the corrected (or "adjusted to be in-correct"? :) ) version
    of function foo(), indeed. No diagnostic is required, and in order
    to produce one, a compiler would have to deduce that *m and *n
    both refer to the same underlying object (the "i" in main), thus
    notice that the line in foo therefore has the undefined effect of
    "i = i++", *and* be coded to complain about that. Even the latter
    is all too rare, and the former requires extensive alias analysis,
    which -- while easy enough in computing theory -- is rare for
    practical reasons (it tends to take a lot of compile-time CPU
    power for little code-improvement).
    --
    In-Real-Life: Chris Torek, Wind River Systems
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://web.torek.net/torek/index.html
    Reading email is like searching for food in the garbage, thanks to spammers.
     
    Chris Torek, Dec 26, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    1
    Views:
    1,239
    Mike Treseler
    Aug 11, 2003
  2. bob

    data recorder examples?

    bob, Oct 31, 2003, in forum: VHDL
    Replies:
    0
    Views:
    533
  3. Boris Boutillier
    Replies:
    0
    Views:
    997
    Boris Boutillier
    Jun 15, 2004
  4. imavroid
    Replies:
    0
    Views:
    853
    imavroid
    Mar 12, 2006
  5. viviane lima - * - * -

    good examples, send links or sources

    viviane lima - * - * -, Jul 31, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    358
    Elliot Rodriguez
    Jul 31, 2003
Loading...

Share This Page