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
In times like this, it's actually fairly useful to be able to read a fair amount of Danish.
Merge branch 'v2022'
Go with 2022.16
Merge branch 'v2022'
Merge branch 'v2022'
Go with 2022.15
Do a shallow clone
Merge branch 'v2022'
Update data to 2025c
Merge branch 'v2022'
Update script for current PHP versions
I hold the domains phpvikinger.{org,net,com}, which are expiring in three months.
I am not going to renew them as I have no use for them any more.
If you're interested, let me know? It'll cost you just the normal registration fees.
I walked 4.8km in 44m52s
I walked 2.1km in 20m46s
I walked 5.8km in 1h12m05s
Robin
They usually never sit still long enough close by for a good photo. But this little bird was perched on this branch for several minutes letting lots of people take photos of it. When I started taking photos, it looked directly at me and my camera — it was clearly posing!
I walked 10.5km in 1h48m41s
I hiked 16.2km in 3h23m19s
Updated a restaurant
Updated a restaurant
I walked 8.7km in 1h25m51s
Merged pull request #1056
Add metadata header to CSV file
RE: https://phpc.social/@Tideways/115859809842500892


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