8000 -Winfinite-recursion when #define NOB_STRIP_PRIFIX from multiple locations · Issue #65 · tsoding/nob.h · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

-Winfinite-recursion when #define NOB_STRIP_PRIFIX from multiple locations #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jjwatt opened this issue May 4, 2025 · 2 comments

Comments

@jjwatt
Copy link
jjwatt commented May 4, 2025

I'm using nob.h both as a build tool and as a library in my program. It's small and I find all the macros immensely useful to have at hand. As a library, I include it from two places: once in the header file because I'm using {Nob,}String_Builder and once in the .c file. I only declare #define NOB_IMPLEMENTATION once, in the .c file. Even so, I get this -Winfinite-recursion warning, which is kind of cool.

(library U:2 ?:4 ✗) wdc cc -Wall -Wextra -o build/wdc src/wdc.c src/main.c
In file included from src/wdc.c:12:
src/nob.h:1562:36: warning: result of comparison of constant 0 with expression of type 'bool' is always false [-Wtautological-constant-compare]
 1562 |     if (rename(old_path, new_path) < 0) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~
src/nob.h:1554:1: warning: all paths through this function will call itself [-Winfinite-recursion]
 1554 | {
      | ^
2 warnings generated.

I'm not using NOB_GO_REBUILD_URSELF in my lib yet. And this is just a warning. I could be doing something wrong. My C is a little rusty. The answer might just be, "don't do that." But, like you, I'm trying to always compile with -Wall and -Wextra, so I thought you might want to know about a case where a warning is generated.

This is probably due to the fact that rename is actually a libc function, which is probably the intended use here. But, if/when NOB_STRIP_PREFIX is defined it's becoming the same function as nob_rename. For now, I just stopped using NOB_STRIP_PREFIX entirely to avoid the warning. That way, it probably avoids any actual possible infinite recursion, too.

@rexim
Copy link
Member
rexim commented May 16, 2025

Oh yeah, this is a known issues. Thank you for the heads up! The workaround is the following

#define NOB_IMPLEMENTATION
#define NOB_STRIP_PREFIX
#include "nob.h"
#undef rename

I'll fix this soon...

@rexim
Copy link
Member
rexim commented May 16, 2025

Should be fixed in 45fa6ef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0