Using Four-Letter Words In Code

When writing firmware and device drivers, it is useful, sometimes, to have human-readable integer values – i.e. integer values that, when you read them in a debugger, mean something distinctive. This is different from using integers that have a distinctive bit pattern so you can read them on a scope (ex. 0xABABABAB, which is 10101011 repeated four times). So, when generating a new magic number, I usually use od, like this

1
2
3
$ echo -n {FOUR-LETTER-WORD} | od -t x1
0000000 50 4f 4e 59
0000004

which would render the magic number 0x504f4e59UL.

Writing this in a piece of documentation often has the effect that the programmer who reads the documentation find his imagination taking off: how many four-letter words does he know? What does 0x504f4e59UL mean? Is it R-rated or X-rated?

Actually, it’s G-rated, as all magic numbers, and all technical documentation, should be. Try it to figure it out, you’ll see.

If you can’t figure it out, leave a comment and I’ll tell you.

Share in top social networks!

About rlc

Software Analyst in embedded systems and C++ programmer. I specialize in systems design, concurrency and language design, and am interested in generic meta-programming and functional programming and their practical applications. I take a pragmatic approach to project management, focusing on the management of risk. I have over a decade of experience as a software professional and a background in science.
This entry was posted in C & C++, Software Design. Bookmark the permalink.

One Response to Using Four-Letter Words In Code

  1. Pingback: The Importance of Patterns « Making Life Easier

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">