Learn C the Hard Way – a lesson where I can’t do too much. Maybe

Ex 8:

This is harder for me to type out with my brain switched off, as it’s new to me so I want to understand it. It’s been pointed out that my wish to understand everything immediately is leading me off down blind alleys. Well, yes. That’s true. I shall try harder not to step off the path, and to trust this book to lead me to where I need to go. I find it hard to stop on the external resea… OK, I find it hard to stop on anything. But I can, so I should. One big risk is that I’ll learn too far ahead and hit a lesson that should be teaching me, and I’ll basically just skim it. I’ve fallen prey to that a lot before. A little learning is a dangerous thing. Although sometimes it can get you cash on game shows, so it’s not all bad.

Extra Credit:

Embedding a null byte in the char name[] increases its size but stops us from reading everything after the null character.

It’s easier to get garbage out of an int than out of a char. I can call for item n+4 out of n in a list of integers and get back what looks like a sensible integer.

If I define an array, I’m defining its size. I can then write out over the end of it, and it stays at the same size (there is a null byte) but I can also pick from it. This gets by the compiler and valgrind. There must be ways of stopping it, presumably tests I can write or flags or some other tool.

Playing with putting characters into ints and ints into characters is… less frustrating than in Python, but probably more dangerous. Python protects me from myself. Here, I can easily put in a character that means something and have it be formatted and it looks right, and it’s just from the wrong place entirely. So I’m pretty damned sure there will be ways of dealing with that. What I need to take from this is that I’ve got the ability to feed X into Y and Y will just chomp it up and not worry about the flavour.

—

Other stuff:

I’m pretty sure that I will use something like sizeof() in the Arduino, if I want to make an array of my LEDs. Sparky needs visual output. Either that or explicit sizing of the … oh. I think I triggered an error over fitting everything into an explicitly sized array when I tried that last time. I probably didn’t have the null character accounted for. So I could try that next time I’m sitting down to program Sparky. That’ll deal with the error where things are the wrong size, and I can look at why they are really not working instead. Sparky’s next due for a look this evening or on Tuesday.