Skip to content

Fix warning when building with -O3#247

Open
ranjeethmahankali wants to merge 1 commit into
tsoding:mainfrom
ranjeethmahankali:main
Open

Fix warning when building with -O3#247
ranjeethmahankali wants to merge 1 commit into
tsoding:mainfrom
ranjeethmahankali:main

Conversation

@ranjeethmahankali

Copy link
Copy Markdown
nob.h: In function ‘nob_read_entire_file’:
nob.h:1676:5: warning: ignoring return value of ‘fread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 1676 |     fread(sb->items + sb->count, m, 1, f);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@rexim

rexim commented Jul 15, 2026

Copy link
Copy Markdown
Member

Compiled on both GCC and Clang with -Wall -Wextra -Wunused-result -O3. Couldn't reproduce.

@theNoof

theNoof commented Jul 15, 2026

Copy link
Copy Markdown

your 'fix' produces new warning for me:

In file included from test.c:2:
nob.h: In function ‘nob_read_entire_file’:
nob.h:2584:18: warning: unused variable ‘nread’ [-Wunused-variable]
 2584 |     size_t const nread = fread(sb->items + sb->count, m, 1, f);
      |                  ^~~~~

assigning it to a variable and then never using it is kinda bad and produces warnings for nearly everyone.

different idea:

...
    (void) fread(sb->items + sb->count, m, 1, f);
...

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

Successfully merging this pull request may close these issues.

3 participants