A union by itself presents some issues, which is why unions are flagged as insecure. I’ve shown some examples in last week’s Lesson. But there is a solution that provides a backstop for consistency when accessing the different data types stored as union members.
Continue reading
Category Archives: Lesson
The Scary Part of the Union
From last week’s Lesson, you saw an example of how different data types stored in a union can be beneficial. As both structures WORDREGS and BYTEREGS overlapped to reflect the data stored in an 8086 CPU, using a union to represent the data is both practical and economic. But such conditions are rare.
Continue reading
Back When Unions Were Useful
Though it’s shunned today, using a union in your C code was common in the 1980s. Back then, compilers and IDEs such as Borland’s TurboC were customized for the MS-DOS operating system. Daring C programmers used the C language’s union keyword to access the system’s hardware directly. Scary.
Continue reading
Unions and Data Storage
A C language keyword worthy of shunning is union. It joins goto as another keyword to avoid, but union is more in the realm of the deprecated gets() function in that it has a potential for dangerous exploits. So why not have some fun with it before the C Lords banish it from the language?
Continue reading
Building a Boolean Array
Continuing from last week’s Lesson, I discovered that though the C language lets you create a Boolean array, the data is stored in char-sized integers and not true binary data. But there is a way to convert that Boolean area into binary data; it just takes some coding legerdemain.
Continue reading
Keeping Up with the Booleans
As a programmer well-versed in Assembly Language, I’m all too familiar with the bits that populate a byte. At the low, low level you find plenty of tools to do bit manipulation. The C language has bitwise operators as well, which remains one of its advantages over the newer, trendier programming languages. So, how does all this fun activity cross over into the realm of the _Bool or bool data type in C?
Continue reading
Booleans
One of the weaknesses of the C language when measured against the newer, trendier programming languages is that it lacks a Boolean type. That is, a variable that’s either one or zero. This issue was addressed with the C99 standard and its addition of the underscore _Bool data type. It’s furthered in the C23 standard with the (better) bool type as well as the true and false keywords available in just about every other programming language used today. It’s time for a deep dive into the binary pool of bool.
Continue reading
Two File Descriptors?
Having two file descriptors available to access the same file might seem redundant. In a way it is. It’s like having two sets of keys to a car: Yes, one could be a backup, but it’s more common that two different people are using the same car. But first, an example is necessary.
Continue reading
Duping a File in the Raw
One of C library functions I find most odd is dup(). I pronounce this function as if it rhymes with cup. I assume others may pronounce it like doop, which rhymes with poop. Whatever. The key is what the function does and how it could even remotely be necessary.
Continue reading
Rubbing a File Raw
About six years ago, I wrote about opening a file in the raw. Specifically, using the open() function to access file data at a low level. This approach uses file descriptors (integers) to track file I/O as opposed to the file handles used by the high-level fopen() family of functions. It turns out that you can do more with raw file access than just read and write data.
Continue reading