microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
10.56k stars 857 forks source link

fix MinGW format string 'unknown conversion type character' warnings #600

Open Novum opened 2 years ago

Novum commented 2 years ago

@sezero noticed that %z does not work properly with MingW, patch here: In case you want to fix this, a patch against vkQuake is here: https://github.com/Novum/vkQuake/pull/498

devnexen commented 2 years ago

Would it be possible for you to create a PR here please ?

Novum commented 2 years ago

I'm not the author. @sezero do you want me to create a PR?

sezero commented 2 years ago

I'm not the author. @sezero do you want me to create a PR?

Yes, please do.

Also make a PR to restrict #pragma comment (lib,"xxx.lib") to msvc, i.e. see https://github.com/Novum/vkQuake/commit/08b0789790a1e14756fe19321c04c6f5d417b13a#diff-08af23c7d272598a9d3e25b98ef6a63fd5793e1e49b1a672a5201c13da7cfd1f

sezero commented 2 years ago

The mingw format string situation turns out to be more annoying: With a gcc switch like -std=gnu11 which turns on _GNU_SOURCE, gcc then emits gnu_printf warnings like: 'I' flag used with '%x' gnu_printf format [-Wformat=]

So, mainstream mimalloc should probably keep its %z usage as is, and we should keep our modifications to ourselves.

Mainstream mimalloc should still restrict #pragma comment (lib,"xxx.lib") to msvc, though.

dscho commented 2 years ago

The mingw format string situation turns out to be more annoying: With a gcc switch like -std=gnu11 which turns on _GNU_SOURCE, gcc then emits gnu_printf warnings like: 'I' flag used with '%x' gnu_printf format [-Wformat=]

Isn't the problem more like __USE_MINGW_ANSI_STDIO being 0 or 1? I would expect --std=gnu11 to imply the latter, in which case %z probably is valid (and the right thing to do). If it is 0, then %I64* is what needs to be used. At least that's what my cursory test using gcc -D__USE_MINGW_ANSI_STDIO=1 -Wall -c -o /tmp/a1.o /tmp/a1.c suggest, where the contents of /tmp/a1.c are:

#include <stdio.h>

int main(int argc, char **argv)
{
    printf("%zx\n", (size_t)-1);
    printf("%I64x\n", (size_t)-1);
    return 0;
}