C examples...?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jwl

    C examples...?

    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
  • Giovanni

    #2
    Re: C examples...?

    jwl wrote:[color=blue]
    > 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[/color]

    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/>

    Comment

    • Rich Gibbs

      #3
      Re: C examples...?

      jwl said the following, on 12/25/04 10:31:[color=blue]
      > 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?
      >[/color]

      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
      rgibbs@alumni.p rinceton.edu

      Comment

      • Malcolm

        #4
        Re: C examples...?

        "jwl" <jwl@nospam.net > wrote[color=blue]
        >
        > 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?
        >[/color]
        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.


        Comment

        • Al Bowers

          #5
          Re: C examples...?



          jwl wrote:[color=blue]
          > 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?
          >[/color]

          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:


          --
          Al Bowers
          Tampa, Fl USA
          mailto: xabowers@myrapi dsys.com (remove the x to send email)
          Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


          Comment

          • Arthur J. O'Dwyer

            #6
            Re: C examples...?


            On Sat, 25 Dec 2004, jwl wrote:[color=blue]
            >
            > 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?[/color]




            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

            Comment

            • infobahn

              #7
              Re: C examples...?

              Giovanni wrote:[color=blue]
              > jwl wrote:
              >[color=green]
              >> 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[/color]
              >
              >
              > 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.[/color]

              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.

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

              Insufficient.

              Comment

              • infobahn

                #8
                Re: C examples...?

                jwl wrote:[color=blue]
                > 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?[/color]

                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.

                Comment

                • Chris Torek

                  #9
                  Re: C examples...?

                  In article <cql93h$9ig$1@t itan.btinternet .com>
                  infobahn <infobahn@btint ernet.com> wrote:[color=blue]
                  >... 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.[/color]

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

                  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."
                  [color=blue]
                  >}
                  >
                  >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.[/color]

                  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.

                  Comment

                  Working...