#defines — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #defines, aggregated by home.social.
-
In the olden daze, a null pointer in C actually was a zero, and it pointed to address zero, and guess what was there? Zeros.
So, a null string pointer pointed to a null string or zero int. And it worked.
And then ANSI C came along, and NULL was no longer a zero pointer to zeroes, and whoa! Stuff broke.
I spent a lot of time reworking the toolchains back then to wrap all of the C library functions via the preprocessor.
Then, I wrote frontends for the libc functions that had the null pointer problem.
Then, I made the build system use my frontend library which trapped the bad code.
So, strcpy() became safe_strcpy() and if a null pointer came in, I would fix it on the fly, and also log the calling code so it could be fixed later.
Oh, I had a common header file that almost all of the code #included so that made it easier. I just changed that common header file to include all of the #defines I needed from another header file, and like magic, all of the source code C calls to strcpy() (example), magically became calls to safe_strcpy(), and then the rest was linker magic because I controlled the build system so I could make it use my frontend wrapper library.