Contributing Advent 4: MongoDB driver variable names
A while ago I started reading Expert C Programming, a book on the intricacies of C, written almost 20 years ago (in 1994). I can very greatly recommend this book, even for seasoned C developers. Even although I know about most of the subjects addressed in the book, I picked up a few new things as well.
Anyway, the book made me look at my default compiler flags again. I tended not to use -Wall at all, but I've since then expanded my CFLAGS to -Wall
-Wextra -Wdeclaration-after-statement -Wmissing-field-initializers
-Wshadow -Wno-unused-parameter. When running with the new flags, the MongoDB driver for PHP started throwing (among others) the following warning during compilation:
/home/derick/dev/php/derickr-mongo-php-driver/bson.c:1069:12: warning: declaration of ‘buffer’ shadows a global declaration [-Wshadow]
char *buffer;
^
At first I found this odd, as I could not find the declaration at all, until I looked closer at the location where the compiler though I had the error:
In file included from /home/derick/dev/php/derickr-mongo-php-driver/bson.c:26:0: /home/derick/dev/php/derickr-mongo-php-driver/php_mongo.h:301:3: warning: shadowed declaration is here [-Wshadow] } buffer; ^
And this pointed me to the buffer struct:
typedef struct {
char *start;
char *pos;
char *end;
} buffer;
This typedef declares buffer into the global scope and therefore the compiler rightfully warns us about this when trying to compile char
*buffer; in a function. The fix was to add the prefix mongo_ so that the new name becomes mongo_buffer. The mongo_ prefix is what we use for all the other structs we define as well.
Life Line
Updated 3 restaurants
I walked 3.1km in 29m25s
I walked 4.4km in 45m01s
I walked 5.4km in 55m28s
Updated a restaurant; Confirmed a hotel
I walked 6.3km in 1h12m59s
Paraphrasing opening keynote speaker at ConFoo: "Should we go back to the waterfall method of writing massive specs upfront to feed to AI coding agents?"
I walked 1.6km in 17m29s
I walked 2.1km in 17m44s
Updated a pub
I walked 2.6km in 26m41s
Merged pull request #1065
Comparison whether class is userland or internal used the wrong macro
PHP 8.6: zend_enum.h now mixes code with declarations
PHP 8.6: Argument names are now stored as zend_strings
Updated a bench and a waste_basket
I walked 8.3km in 1h25m37s
Created a recycling
I walked 10.5km in 1h46m57s
An interesting journey in story form, showing how English changed over time.
https://www.deadlanguagesociety.com/p/how-far-back-in-time-understand-english
A much better writer than I is summing up perfectly why I have such disdain for Generative AI/LLMs.
https://jonn.substack.com/p/so-why-do-i-feel-so-angry-about-this
Created a waste_basket; Updated a waste_basket; Deleted a bench
Created a bench; Updated 7 benches and a gate; Deleted 2 benches and a gate
Created 10 benches and 2 waste_baskets; Updated an information


Shortlink
This article has a short URL available: https://drck.me/adv1304-aet