Saturday, February 04, 2023
Notes about an overheard conversation while driving home
“Why the convoluted way home?”
“Are you driving?”
“No. I'm just curious.”
“Because you told me to go around.”
“I told you to get into the other lane to go around the bus!”
“No, you just told me to go around.”
“Around. Besides, this way, I don't have to take a left turn.”
“Argument of last resort, I see.”
Monday, February 13, 2023
The Nile is nice this time of year
On Friday, February 3rd, I broke my glasses. I was out and someone complemented me on my shades. I pointed out that they were just clip on shades, but I went further to show that my glasses were flexible. That's when I snapped off the left arm of my glasses at the hinge. In retrospect, I should not have done that.
But they were nineteen years old. And it was clear to Bunny that I needed new glasses anyway. As she keeps pointing out, my glasses would slowly creep down my face, but that was only to keep things in focus. It had nothing to do with my eye sight changing.
But now I had no excuse. The next day I picked out new frames (Flexon, same manufactorer as my old ones). One of the store employees tried to fix my existing pair of glasses with tape, and all I can say about that—it was an attempt. The employee also managed to knock off the nose pad on the left side of my glasses (sigh) so now the glasses were even less stable on my face than before. I did manage to get an appointment for an eye exam on Monday the 6th.
Monday, and I go for the exam. Things were going well until the end, when the doctor pointed out that it was time for me to get progressive lenses. Or, you know, bifocals.
No! I am not that old! I don't need bifocals! I'm still only … um … oh … mumblety-mum years old.
Man, the Nile is a nice place, isn't it?
I could expect the new glasses to be ready in seven to ten days.
Eight days of my old glasses falling off my face (and constantly adjusting them when they don't), and my new glasses are ready. With “progressive” lenses. I have up to 30 days to decide if I like them, and if I don't, I can get … sigh … bifocals.
The progressive lenses are weird. Parts of my peripheral vision are blurry. If I move my head back and forth, surfaces along the bottom of my glasses undulate in an unnerving manner. Sometimes when I tilt my head, it feels like (to borrow a movie term) a zoom-in but with improper focusing. It's trippy, but without the side effects of a bad drug trip.
We'll see if I can get used to them.
Oh, and one more amusing fact about my new glasses—the lenses are so think at the edges, that the arms don't fold down all the way.
Thursday, February 16, 2023
I guess now Bunny can add “upholsterer” to her list of hobbies
A few weeks ago, the top arm coverings of my office chair basically crumbled and fell off.
The old coverings were some combination of rubber and plastic and I guess over time, they just became brittle or dried out, and fell apart. This exposed the underlying hard plastic frame underneath. It wouldn't be that bad actually, except for all the square holes, used to both lessen the amount of hard plastic required, and to give the old covers something to grip onto.
Resting my arms on the bare arm rests is uncomfortable—it's not exactly cutting into my skin, but I can feel the square holes which is unpleasant, and left a square pattern on my arms. My idea was to take some foam and wrap some cloth type material around it and the plastic frame. But it was Bunny who made the new covers from material lying about Chez Boca.
It's basically a tube of cloth wrapping the foam, with some extra material folded back onto itself to form some flaps to go around the ends of the arm rests. Here I am demonstrating how it works with my fingers.
The material has some stretch ability, which helps to keep it on the arm rests.
It adds a nice bit of color to the chair, and it's a lot more confortable than the old covering. Nice job indeed!
Thursday, February 23, 2023
A breakdown of the triple-star pointer
I few days ago I read “Lessons learnt while trying to modernize some C code”
and one of the problems of C stated stood out to me: “Avoid constructs like
char ***. I thought it was a joke, but people do
char *** and it’s insane—almost impossible to comprehend why
do you need a pointer to a pointer to a pointer.”
but come on!
That doesn't happen often enough to complain about!
And then I found one in my own code!
at least I can explain why I needed a
It's not insane,
and it's not impossible to comprehend why.
I'll start with
that means “string”
(the exceptions are just that—exceptions).
We can replace
char * with
typedef char *cstring which gets rid of one “*”,
when you see
int main(int argc,char **argv),
it generally has the meaning of an array of strings:
int main(int argc,char *argv).
Sometimes it could mean just a pointer to a pointer,
but I'm using the “array of strings” meaning in my code.
Translated using the custom type I defined above,
char ** becomes becomes
cstring  and
char *** becomes
cstring *—a pointer to an array of strings.
And this idiom,
when it happens,
usually means the callee is going to allocate the memory for the array of strings and return it via the pointer.
Which is exactly what the function I wrote does.
So when I expect a
char *** here,
what I'm asking for is a pointer to an array of strings
(aka character pointers or character arrays).
The only thing insane about this is the syntax,
and maybe the semantics
(pointers and arrays are near enough the same that it's dangerous)
but I've been working with C long enough that I just kind of accept it.
just don't ask about
char ****—that's just silly talk!
Discussions about this entry
- A breakdown of the triple-star pointer | Lobsters
- A breakdown of the triple-star pointer | Hacker News
Friday, February 24, 2023
A branchless segment of code to generate a printable hexadecimal value
I was an avid fan of assembly language back in my youth and I did a lot of it. And in that time, if I needed to convert a 4-bit quantity to a hexadecimal character, I would write the obvious code:
; x86 code add al,'0' cmp al,'9' ; if '0'-'9', no adjustment needed jbe skip ; otherwise, we need to adjust add al,7 ; the resulting character by 7 ; to get 'A'-'F' skip:
Eight bytes and a branch instruction, and not many ways I could see to improve on that, until the other day when I came across this bit of code:
; x86 code add al,90h daa adc al,40h daa
Not only does this convert a 4-bit value to a hexadecial character, but it's two bytes shorter and it's branchless!
some might say this abuses the
but it works.
And how it works is pretty clever I think.
DAA instruction exists to allow BCD
(back when it was a thing).
For each 4-bits in a byte,
DAA instruction will check to see if it's in the range of 10 to 15 and if so,
add 6 to that 4-bit value to bring it back into the 0 to 9 range,
and propagate a carry bit
it's a bit more involved than that,
but that will suffice for this post—you can check my MC6809 emulator for the gory details of the
By adding 0x90 (or 144 in decimal) to a 4-bit value then using
a carry bit will be propagated if the initial value was 10 to 15;
otherwise there's no carry to propagate.
ADC of 0x40 (or 64 decimal) will then add any carry of the previous two instructions into the lower four bits of the result,
DAA will then adjust the upper 4-bits to be either 0x3 or 0x4 due to the previous addition of 0x90
(which causes the number to act like a negative number if the initial value was bewteen 0 and 9).
And because of the carry if the initial 4-bit value was between 10 to 15,
you get the required adjustment of 7 needed for values of 10 through 15.
This means the result is 0x30 to 0x39 (the ASCII values of “0” to “9”) of the 4-bit values of 0 through 9, or 0x41 to 0x46 (the ASCII values of “A” to “F”) for values 10 through 15.
Quite ingenious really.
I found reference to what may be the origin of this sequence: the article “A Design Philosophy for Microcomputer Architectures” from the February 1977 edition of Computer (the code appears on the third page of the article), but it's unclear if the author came up with this on his own, or it was a known sequence at the time.
I just wish I found out about it earlier.