Learn C the Hard Way – Lucky I already thought of that

Because I was remapping the keyboard, I left my terminal in root, and ended up creating an exercise as root. So later, I couldn’t amend it. Options were chown, chmod, or just leaving it there and not caring. Fortunately, I already had exercise expansions and extra credit as different files, so it didn’t affect me. However, pro-tip here; don’t do that.

Learn C the Hard Way – Arch is a bastard for this and I’m fine with that

Ex 4.

Valgrind is available in the /extra repository in Arch. We’re going to make it ourselves, though. Fair enough. I’ve made a few packages as far as I recall, but not in a while. When I was initially setting up my machine, inkscape wasn’t so good and I was using inkscape-bzr and now I don’t need that any more.

$ tar -xf <FILE>

is enough to unpack most things. ‘eXtract File’. The tool will work out what sort of file it’s working on and just does it.

$ ./configure

– error. Valgrind works on kernels 2.4 and 2.6 – Arch is a rolling release. I’m on kernel 4.something. Soooo. Package manager it is. At some point I’ll need to work out what about the package has been changed to make it work in Arch. The README.aarch has instructions on cross-compiling and paths and hosts which have a shape that makes sense but I’m not looking at the detail. I’ve used pacman and I have valgrind on the system. I stared at the Makefiles that my attempt generated, though, in the hope of absorbing their strength by drooling. On with the lesson.

The output of valgrind is already similar to Zed’s, but at some point I may diverge – Arch is like that. For now, though, I’m getting error tracking.

By fixing the uninitialised variable in ex 4, I fix all the actual errors. This is odd, as valgrind doesn’t pick up the %d without a related integer, in the first printf function. I can’t see why that might be in the manual. However, I know what the program should say, so I know what to fix. An uninitialised variable is an error that could lead to unexpected problems, and valgrind picks it up. A variable that’s missing could lead to, well, also unexpected problems. But valgrind doesn’t pick it up. Odd. Maybe an Arch thing but I don’t think so. It was not there in Zed’s print-out either.

The compiler tells me what the other problem is, so I’ll deal with that. Variables are now initialised and don’t go unused, and all format sequences are filled.

I did some messing about with making downloaded packages, but I’ve got to look into Arch’s installation process to really understand that. pacman is a powerful tool, and like all powerful tools, it hates me right from the off. I know I can make a package and then have pacman install it from my local file, but for now I’m not using that. Onward, upward, and avoid the Pevensey children on the way.

Learn C the Hard Way – placeholders, thingies, format strings, and my brain holding too much

Ex 3:

Easy enough. I had to look up exactly what a format string was, but that’s fine. Zed flagged it up for looking. This is quite a lot like Python’s %s and %d functionality. Just different syntax.

So, trying to break the printfile, I found that

printf("%c", height);

would look up height (an int that gave numeric value) and find it was 72. So it would then look up the character 72 in ASCII, and return an upper case H. That’s the DEC version, by default.

Unicode gives me a WTF character. I assume I need a different library to deal with that.

A missing age variable gives me a ludicrous age, but doesn’t crash the program. I can embed the width of the returned number or string in the %symbol by using %+4i – width of 4 digits, including a sign that will always be shown or %10.3f – that would give a minimum width of 10 digits including a decimal point, and 3 figures after the point. A – will left justify shit. I’ve been told that C is really concise, and that’s a good example of using not very many characters to type stuff. It’s not exactly confusing form with function – the format characters sit over the stringy bits. They just sit over it inside the same bit of typing.

r is a return to the start of the line without a new line. I can overwrite the earlier part of a string with it.

So, I’ve got various ways of breaking printf(), but those are mostly bad typing. I can also accidentally cover over a result, or leave big spaces in a result.

The last bit of the Extra Credit wouldn’t be clear if I hadn’t done a bit of research already. The ‘list’ of the makefile isn’t, I think, a thing Zed’s defined. In Ex 2 I cleaned up a bit when I took out ex1 as a dependency for all:. Now, I’m going to make it so ‘clean’ and ‘all’ have the lists I want inside them. For the moment I’m typing out all the names, but I’m aware there’s a way I can substitute in everything that’s in a folder, and stuff like that. I don’t mind having had to look up what the list and the dependencies were – Zed’s trying to make new programmers thing for themselves. I am concerned I’ll be trying to look up too much, which is a problem I always have. Knowing when to stop is a skill you don’t pick up until you know what’s important, and you don’t know what’s important until you’ve practiced for a while. So, every time my brain seems too full, I’ve probably gone too far.

www.le.ac.uk/users/rjm1/cotter/page_31.htm has a good list of width/precision stuff, but the examples are odd.

printf("%s,Hello")

– I’ve eMailed the owner there to ask how the heck* that works. It breaks my program by printing out the last parts of my previous lines. It compiles (badly) and then it betrays me. Le whut?

* I used different words.

It’s all downhill from here

This is a blog dedicated to the making that Diana does, often in the company of others, often to the exclusion of eating, sleeping, or personal hygiene. It’s also dedicated to those who help her, and those who glaze over and rock quietly when she talks to them.

You helped!

It’s a space in which learning will often be accompanied by failure and the word ‘fuck’ whispered quietly but vehemently as the magic smoke escapes from something expensive, or with a tiny grinding sound, a drill bit breaks in a piece of steel.

Fuck.