The C11 standard added the “underscore” bunch to the C language’s traditional keywords:
I don’t routinely use any of these in my programs, beyond trying a few out to see how they work. The _Bool keyword comes in handy. The rest? Well, they’re worth exploring from a curiosity standpoint. For this week’s Lesson, I reveal the mysteries of the _Generic keyword.
My approach for initializing a buffer is to use a loop and assign each byte a value such as zero or the null character,
'\0'. It’s tedious, but necessary. And for the impatient, some functions are available to perform this task for you.
When my code requires a random odd buffer, I generally assign it a given size in some holy computer value: 16, 32, 64, and so on. But a defined constant exists,
BUFSIZ, that can also be used to set a buffer size safely and consistently on all C compilers.
The defined constant
NULL represents a null or empty pointer. I’ve written before that the constant isn’t defined as zero, though such an assumption could lead you into trouble.
Mathematicians truly enjoy doing their math thing. As a mortal human, I don’t have a spot for math things on my “fun” spectrum. Yet, one of the more jolly things the math nerds do is discuss the value zero.
I recall the math class where negative numbers were introduced. I was appalled. From Star Trek, I easily accepted the concept of antimatter, but the notion of negative values deeply offended me.
The strfmon() function, introduced in last week’s Lesson properly formats a monetary value for specific regions. To unlock the function’s various features, you must understand and use formatting placeholders.
The C programming language doesn’t sport the thousands of functions (or methods or what-have-you) available in Java. They say Java programmers may never use or even know the variety. With many fewer functions available in the standard C library, I would think to know them all. Then along comes another one I’ve neither used nor heard of. This week’s Lesson covers such as function, strfmon().
Many moons ago, I wrote about the non-standard function, strcasecmp(). It works like the C library function strcmp(), though it ignores character case. Turns out my return value from the function isn’t exactly correct.
The 16-hour puzzle presented in last week’s Lesson has been resolved: It was actually a 24-hour puzzle, minus 8 hours for my time zone, which equals 16 hours. But what can be done about the time zone difference?