The boring rants of a lazy nerd
Saturday, January 24, 2004
learning and teaching
I once heard or read something that could be paraphrased as: "the best way to learn something is to try and teach it", meaning if you can explain it so that another person understands, you understand it yourself. In my experience it is true - explaining a thing to another person forces one to organize one's own thoughts. Doesn't have to be a real live student, but a real response helps to gauge your success (or lack there of).
Be advised: The following is programming gibberish. You have been warned.
So, I was trying to further shorten my sig (currently it's 74 characters long) by changing the time when the output is done from after to before the recursive function call. This necessarily reverses the printing order, which forced me to re-calculate the numerical value of the four character string. Being a lazy coder, I have promptly written a single printf that prints the integer value of a literal string constant by casting a char pointer to an int pointer. This has lead to a surprising result. Since printing an int as a character should print the character corresponding to the numerical value of the least significant byte in the machine's character set and codepage (Latin-1 extended ASCII, in this particular case), the fourth character should've been printed, but instead it was the first that showed up in the program's stdout stream.
I have pondered the representation of a 32bit int in machine memory and reached the conclusion that I have not taken endianes into account. I grudgingly admitted to myself that fancy development environments featuring advanced source code debugging have mellowed my innate geekines and used my laziness to dumb me down to script-kiddie level. Well, no more! I will figure it out even if I have to disassemble it! Especially if I have to disassemble it, because I think hexadecimal is kind of fun. Now I'll make a little observation that while writing this I'm imagining the chances of me ever getting a girlfriend plummet like stockbrokers in October '29, but back to the business at hand - I'm working on an x86, IA-32 machine which is, as many know, little endian. That means the least significant byte in a four-byte int is actually stored first in memory.
In order for me to make sure my understanding of the matter is full, I've decided to explain it to someone else. Being a reclusive and an only child, my options were rather limited: a cooking father and a newspaper reading mother. I could've of course IM'd one of my few friends, who have the distinct advantage of knowing this stuff themselves, but I couldn't have been bothered at the time. So I explained memory mapping multibyte data blocks to my mom, including the borrowing of the two approach’s names from Jonathan Swift. She patiently sat through it all and got it. If you’re wondering, she has no experience with programming whatsoever. I’m very proud of her and even more thankful for having such great parents. *angelic smile, nimbus*
Subscribe to:
Post Comments (Atom)
About Me
- Wolf550e
- GCS d- s-: a-- C++$ UL++ P+++ L+++ E--- W+++ N o? K? w++$ !O !M !V PS-(+) PE Y+ PGP+(-) t--@ 5++(+++) !X R-- tv-- b+>++ DI+++ D+ G e h! r* y--(-)>+++
No comments:
Post a Comment