Skip to content

C: Introduce string_equals utility function#1130

Merged
marcoroth merged 3 commits intomarcoroth:mainfrom
citizen428:string-utils
Feb 7, 2026
Merged

C: Introduce string_equals utility function#1130
marcoroth merged 3 commits intomarcoroth:mainfrom
citizen428:string-utils

Conversation

@citizen428
Copy link
Contributor

@citizen428 citizen428 commented Feb 6, 2026

Note: this was built on top of #1129, which should be merged first. I didn't want to update the already removed visit subcommand.

This PR introduces a string utility function called string_equals and updates usages of strcmp to use that instead.

Rationale:
While perusing main.c, I found the repetitive strcmp calls a bit of a nuisance. I originally considered adding the following macro:

#define STRING_EQ(a, b) (strcmp((a), (b)) == 0)

However, since we're targeting C99, we can also use a static inline function instead.

File size considerations:
I built the binary on my machine with both the strcmp and string_equals versions. As expected, with our production flags, this resulted in no increased binary size as clang successfully inlines all the calls. For debug builds, there's an increase of 448 bytes, which I think is a reasonable tradeoff for the increased readability.

Build strcmp string_eq Diff
Debug 841,208 bytes 841,656 bytes +448 bytes (+0.05%)
Production 649,960 bytes 649,960 bytes 0 bytes

Open question:
Are we actually using the production flags to build releases? The assigned variable is never used in the Makefile.

#include <stdbool.h>
#include <string.h>

static inline bool string_eq(const char* a, const char* b) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is a header-only definition, which is common for this type of static inline function to ensure every compilation unit has its copy of the function.

@marcoroth marcoroth changed the title Introduce string_eq utility function C: Introduce string_eq utility function Feb 6, 2026
@citizen428
Copy link
Contributor Author

@marcoroth Renamed everything as requested.

@marcoroth marcoroth changed the title C: Introduce string_eq utility function C: Introduce string_equals utility function Feb 7, 2026
Signed-off-by: Marco Roth <marco.roth@intergga.ch>
Copy link
Owner

@marcoroth marcoroth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @citizen428! 🙏🏼

@marcoroth marcoroth merged commit f7d0e66 into marcoroth:main Feb 7, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants