Reader Chris pointed out a fun and common C language inconsistency in last week’s Lesson: The constant M_PI isn’t always available. It’s not defined as part of the C standard, which means your compiler may lack this handy shortcut, located in the math.h header file. What to do, what to do?
Continue reading
Category Archives: Lesson
π Day
Mathematic geeks of the world celebrate March 14 as “pi day.” The logic is that the date is 3/14, which are the first three digits of the value π, or 3.14159….∞
Continue reading
From the C Relic File: auto
Of all the C language keywords you don’t use, auto is probably the most memorable. That’s because it’s listed first among the canonical table of 32 C language keywords. Yet, in all the code you’ve written or seen, auto is seldom used if at all. So what does it do and is it even necessary?
Continue reading
Variable Width Values in Conversion Characters
The topic of conversion characters, or printf() percent placeholders, is vast and confusing. Most programmers know the basics, but the details are so complex that some handy shortcuts are overlooked. One of those shortcuts is the * wildcard that sets width values.
Continue reading
More Fun with _Bool
Plenty of C coders implemented boolean variables long before the C99 standard introduced the _Bool type. Programmers defined TRUE and FALSE constants, they used char or short variables as toggles, or they manipulated bits in a byte to simulate binary and boolean operations. With all that going on, you’d think adding a boolean variable type to C and calling it bool would have been a no-brainer. It wasn’t.
Continue reading
Ruminations on the _Bool variable type
One of the C language keywords added in the C99 update is _Bool. It’s an underscore keyword, which means it lacks the respect gained by the other keywords — even the useless ones like auto.
Continue reading
Is continue Necessary?
On this blog, I try to show examples for all the C language keywords, but continue is one I struggle with. It doesn’t appear in Beginning Programming with C For Dummies. It barely appears in my C All-in-one Desktop Reference For Dummies. Even the venerable K&R manual has difficulty explaining how this keyword is worthy.
Continue reading
The Perils of typedef
The typedef keyword is both handy and dangerous. It’s handy because it allows the pantheon of C variable types to be expressed in different ways. It’s dangerous for the same reason.
Continue reading
Playing with a Double-Linked List
In last week’s Lesson, I demonstrated code that builds a double-linked list: Each structure in the list references both the next structure and the previous structure. The first and last structure addresses are saved. And NULL pointers within the list its start and end. How all that junk becomes useful is apparent as you work with the list.
Continue reading
Building a Double-Linked List
Similar to a linked list, a double-linked list requires that you work on both the current item in the list as well as the the previous item. You just have one additional structure member to update, which is the pointer from the current item to the previous structure.
Continue reading