Learn C the Hard Way – I do everything the hard way

For those joining me in my world record yak shaving attempt, today I started poking at Learn C The Hard Way by Zed Shaw. It’s currently in its beta form, as he’s writing it in public so people can look and learn and proof-read, and I have a reason to learn enough C to get by. Sparky, the Spark Eroder, needs an output method to help me understand what’s going on in his insides. I can’t afford an oscilloscope, so a £3 microprocessor is going to do the job.

I say ‘a’ microprocessor, but when I bricked the first, I ordered two more. If I’d bricked an oscilloscope, two more would have come in beyond budget.

So, Zed has written up the two cases of Debian and RPM based Fedora, for the installation of what I’ll need. I work on Arch. There are reasons. They are not and can never be adequate reasons, but I’m sticking to them. So, the first thing I did was Exercise 1, to see what would break. If I could make Ex 1 work, then I’d be set up right. If not, I’d have error messages.

I had error messages!

ex1.c: In function 'main':
ex1.c:3: warning: implicit declaration of function 'puts'

Well, he explains this in the Ex 1 page – I’ve got flags set that will show errors. This one is a warning, and if I were on Debian or Fedora or in fact anything sane, it (probably) wouldn’t be a problem. But I’m not, and it is. So now I have to work out WTF the flags have to be. He can show me how to turn the flags /on/ and break things. I’m looking to turn the flags /off/ and mend things, or at least suppress them so I live in bliss and ignorance.

Turning flags off in the future is probably a bad idea, and I’m going top be keeping them on in general, so if I run into this again I can flag it up, but I want to know how it’s going wrong. It also meant I didn’t type the version with the flags turned on.

$ man make

It seems that there’s a –warn-undefined-variables flag, but I can’t work out how to turn it off. There’s also a –touch flag, which is interesting. It’ll just poke (and possible create, I wasn’t doing more than skimming) files so they have updated timings for when I want to make a latest version of a set of files. That’s probably not useful for me yet, but the notion that


is so powerful is written all over the manual file. I can define different files as the ones to use, regardless of which are most recent, and I can deliberately override dependencies. So that tells me that make handles dependencies and stuff like that.

On with the show. I can make, and use, ‘ex1.c’. It prints ‘Hello World.’. It’s a capital letter on the second word because that’s how I roll. Oddly, I’ve found that the tighter my copying of code gets, and the more I’m concentrating, the more likely I am to typo in the parts where there’s no penalty for error.

Extra Credit:

I didn’t edit the original exercise file. I made a second file so I’d be typing the same things again, so I’ve got ex1a as well as ex1. I’m pretty sure that’s better, as I can compare programs if I have to.

I worked out what stdio has to stand for. It’s not short for Studio. It means ‘standard in-out’. The ‘.h’ means it’s a header file. I looked up the second bit. The first bit I knew through failing repeatedly at Linux everything, and I’m OK with that.

I managed to get a segmentation fault by using ‘ instead of ” as line breaks. I also need a work-around for my American keyboard which doesn’t play nicely with my locale settings. I’m going to have to give up the £ to get a # and a working pipe that doesn’t need five key presses and a swift prayer.

man 3 puts

– The ‘3’ means it’s in part 3 of the linux user manual, which deals with C library functions. So,


means you’re explicitly declaring the existence of puts() in the library you include, instead of implicitly calling it and relying on the compiler to make up for your error.