k+r book

Discussion in 'Mac Programming' started by jamesapp, Jun 11, 2008.

  1. jamesapp macrumors 6502a

    Mar 7, 2008
    reading from a book The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie. In the last chapter of the book, they discuss a file called syscalls.h,

    from the book:

    "We have collected function prototypes for the system calls into a file called syscalls.h so we can include it in the programs of this chapter. This name is not standard however."

    I don't know where these functions are coming from.
    the first program in the chapter is a program to copy input to output.
    here is my source file which i called inputout.c:

    #include "syscalls.h"
    main()  /* copy input to output */
      char buf[BUFSIZ];
      int n;
      while ((n = read(0, buf, BUFSIZ)) > 0)
          write(1, buf, n);
      return 0;
    when i went to compile it i got error messages saying that the file syscalls.h doesen't exist. does anyone know anything about syscalls.h?
  2. brn2ski00 macrumors 68020


    Aug 16, 2007
    That was the same book that I used in college as well. Small world....

    It sounds like syscalls.h is a KR specific header file. You may need to install or copy those files from (where ever) into your directory where the program is.
  3. drivefast macrumors regular

    Mar 13, 2008
    #include "stdio.h"
    instead of syscalls.h. maybe the syscalls.h they have in the book already includes stdio.
  4. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    It is possibly the most popular C programming book out. I wouldn't be surprised if the majority of C programmers owned it.
  5. ChrisA macrumors G4

    Jan 5, 2006
    Redondo Beach, California
    K&R is a good book to have for historic reasons. It shows what programming C was like in the early days before ANSI C was the standard. I keep my copy of K&R right next to Griiswald's "SNOBOL" book, the MIT LISP 1.4 manual and Wirth's Pascal book. All of these are classics that are decades out of date. I got into programming back when Unix was the hot new thing in the early 70s

    Today if you don't know what dot-H file to include just look up the man page for that funtion. I cut and paste the #include right out of the man page. After doing this a few times you learn the common ones.
  6. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    The 2nd Ed is ANSI C which is all you really need at the moment considering the failure of C99 to hit full mainstream adoption.
  7. ScoobyMcDoo macrumors 65816

    Nov 26, 2007
    Austin, TX
    Hmmm. I have the first edition still - it doesn't mention the syscalls.h file. Not sure why it would for that example. On my linux box, there is a syscalls.h file, but it would not be needed for this example.

    As ChrisA said, use the man page - in your case type "man 2 read" and it will tell you what headers you need to include:

    pread, read, readv -- read input

    Standard C Library (libc, -lc)

    #include <sys/types.h>
    #include <sys/uio.h>
    #include <unistd.h>
  8. pilotError macrumors 68020


    Apr 12, 2006
    Long Island
    In chapter 1 or 2 of the book, they created a header for all the future examples in the book. That's what the include file is.

    I'm sure if you look in the TOC, you'll find the page number of the listing.
  9. psingh01 macrumors 65816

    Apr 19, 2004
    sounds like it is a file they created themselves like other say. might even be listed in the book.

Share This Page