Skip to content

Suppress Compiler Warnings for Unused Functions - #2007

Closed
nlordell wants to merge 1 commit into
nothings:masterfrom
nlordell:fix/unused-jpeg-fns
Closed

nlordell wants to merge 1 commit into
nothings:masterfrom
nlordell:fix/unused-jpeg-fns

Conversation

@nlordell

Copy link
Copy Markdown

Both stb__addints_valid and stb__mul2shorts_valid are only used by the JPEG decoder and generate unused function warnings when not compiling with JPEG support:

// unused.c
#define STBI_NO_JPEG
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
$ cc -Wunused-function -c unused.c -o unused.o
In file included from unused.c:3:
./stb_image.h:1070:12: warning: unused function 'stbi__addints_valid' [-Wunused-function]
 1070 | static int stbi__addints_valid(int a, int b)
      |            ^~~~~~~~~~~~~~~~~~~
./stb_image.h:1078:12: warning: unused function 'stbi__mul2shorts_valid' [-Wunused-function]
 1078 | static int stbi__mul2shorts_valid(int a, int b)
      |            ^~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

Just #if them out if not building with JPEG support. I used two separate #if blocks, one for each function, as that appeared to be the generally preferred pattern.

Both `stb__addints_valid` and `stb__mul2shorts_valid` are only used
by the JPEG decoder and generate unused function warnings when not
compiling with JPEG support:

```c
// unused.c
```

```
$ cc -Wunused-function -c unused.c -o unused.o
In file included from unused.c:3:
./stb_image.h:1070:12: warning: unused function 'stbi__addints_valid' [-Wunused-function]
 1070 | static int stbi__addints_valid(int a, int b)
      |            ^~~~~~~~~~~~~~~~~~~
./stb_image.h:1078:12: warning: unused function 'stbi__mul2shorts_valid' [-Wunused-function]
 1078 | static int stbi__mul2shorts_valid(int a, int b)
      |            ^~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
```

Just `#if` them out if not building with JPEG support. I used two
separate `#if` blocks, one for each function, as that appeared to
be the generally preferred pattern.
@nlordell

Copy link
Copy Markdown
Author

Note that I did not add myself to the "Bug & warning fixes" contributor list, to avoid unnecessary merge conflicts. I generally don't mind being left out, especially for such a tiny contribution like this one.

@rygorous

Copy link
Copy Markdown
Collaborator

This is fixed in the dev branch, although other changes have since made this exact set of conditions incorrect - GIF now also depends on stbi__addints_valid. Closing this PR.

@rygorous rygorous closed this Oct 29, 2026
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.

3 participants