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
I've just finished reading "Snow Crash" by Neal Stephenson. I found this a fun and excellent read.
Updated a restaurant
Updated a restaurant
Updated a restaurant
Updated a restaurant
Updated a brewery
Updated a restaurant
Updated a restaurant
Having dessert before even attempting to go to the restaurant for my (early) birthday dinner.
Enjoying this barrel aged quadrupal, in entirely new Dutch city (another Christmas tradition for us).
Updated a bar
Updated a restaurant
Updated a pub
Updated a bar
Updated a restaurant
Updated an attraction and a museum
Updated a restaurant
Updated a bar
Updated a brewery
I walked 7.4km in 1h17m31s
I walked 1.0km in 8m59s
I know my French is pretty terrible, but I'm sure I'm closer to the correct answer than what's shown here...
I walked 1.2km in 12m04s
I walked 6.4km in 1h11m52s
Merge branch 'v2022'
Merge pull request #169 from psumbera/solaris-2




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