Ex2: Not sure if I misread things

On page 11 in the printed book, the “What You Should See” (Exercise 2 Session) at the bottom says I should be getting a warning for implicit declaration of function 'puts’. Overleaf on page 12 the top block is a warning that “If you fixed ex1.c to have #include <stdio.h>, then your output won’t have the warning (which should really be an error) about printf. I have the error here because I didn’t fix it.”

I didn’t get a warning for either printf or puts. I looked through the book and the repository of example code on github, and tried to check my own work, but I can’t seem to figure out where I went wrong:

1.) Page 6 has us putting in #include <stdio.h> right at the beginning; I couldn’t find any specific instructions to take it out.

2.) Is ‘puts’ a typo or did I unknowingly skip a section? I looked up both functions and muddled my way through their man pages, and I believe they both print things to the console.

3.) I tried commented out the #include to see what would happen and got a slightly different error than anticipated:

"warning: incompatible implicit declaration of built-in function ‘printf’
ex1.c:9:5: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’

Is this expected behavior?

4.) On page 11, are we first creating a file called ex2.1.mak, then saving a copy of it as Makefile so that there’s two files with different names but identical contents? I’m not sure if I read that part correctly either.

In case the platform or versions matter, I’m running a 64-bit Linux VM (Arch distribution) in VirtualBox, on a Windows 7 laptop. Using --version flags, the shell says I’m using GCC 8.1.0, GNU Make 4.2.1, and GNU bash 4.4.19(1).

I apologize in advance for how dense these questions must seem, but I’m trying to take the core competency of Attention to Detail to heart and not blindly rush ahead without checking my work.

Let me hit these one at a time:

  1. That may be an editing mistake, but take it out and see if you get a warning. Then try compiling with -Wall and see if you get an error or warning.
  2. The puts function is basically another way to use printf that nobody uses. Again that might be an editing mistake so I’d have to go look at the specific problem.
  3. Yes, that’s one of the errors you should get. I guess they’ve been improving them since that’s a much clearer error message with exactly what you should do to fix it.
  4. If you want to name it if you’re referring to the name of the file above the block of code then that is mostly just to tag it as the exact file. Save it as Makefile, but if you want to use ex2.1.mak to keep your files straight then run: make -f ex2.1.mak

These are all great. I haven’t visited the C book in a while so probably things have changed since then. I’d say you may have to work around little platform shifts like this as you work.

Thanks very much! I’m relieved to know I wasn’t completely off track.

I hope painting is going well for you, and I’ll try to keep a list of suspected editing mistakes (if you want them).

Take care!