in reply to Re^2: [XS] : "snprintf" portability options
in thread [XS] : "snprintf" portability options

oh-so-thoughtfully re-introduces the issue

No it doesn't. The issue is there with or without the -Wformat. Your sarcasm is misplaced since the warning isn't spurious. The issue is that the wrong format is being used. This is a real error that needs fixing.

Replies are listed 'Best First'.
Re^4: [XS] : "snprintf" portability options
by tonyc (Friar) on Sep 16, 2024 at 22:56 UTC

    The warning is spurious, %I64u is valid on Windows. Unfortunately with the macro the full text of the format is hidden so all you have is the misleading "%u" from the base message:

    C:\Users\Tony\dev\perl\git>gcc -Wformat -oint64.exe int64.c int64.c: In function 'main': int64.c:6:15: warning: format '%u' expects argument of type 'unsigned +int', but argument 2 has type 'long long unsigned int' [-Wformat=] 6 | printf("%I64u\n", x); | ~~~~^ ~ | | | | | long long unsigned int | unsigned int | %I64llu C:\Users\Tony\dev\perl\git>type int64.c #include <stdio.h> unsigned long long x = 0; int main() { printf("%I64u\n", x); }

    If it is a bug, it's a bug in perl, since that's where the macro OP is using comes from.

    I've considered changing the Win32 config in perl to use "%llu"/"%lld" instead, but testing against the older versions of MSVCRT in older Windows that we theoretically support is difficult.

      If it is a bug, it's a bug in perl

      Don't you mean a bug in gcc? gcc knows it is building for the MS libc, so it should accept the patterns known to work for that libc.

        I was looking at it from the point of view that the "%I64u" format is incorrect, though it works and perl's own implementation of formatted output emulates it.

        If I could be sure old MSVCRT supported "%llu" I'd make a PR switching it to the standard form, since it would let us turn on -Wformat and better detect format issues on the specialness that is Win32. And reduce confusion from people wondering what this I64 format business is.

      Bad test. You just repeated what was already said. But replacing 0 with 9223372036854775808ull does make your point.

      So the compiler is wrong about the expected format. wow!

      And thankfully, it still provides the expected format.

      If it is a bug, it's a bug in perl

      It's a bug in gcc. The format expects a unsigned long long, but it claims it expects an unsigned.

Re^4: [XS] : "snprintf" portability options
by etj (Priest) on Sep 16, 2024 at 13:09 UTC
    jdporter or someone - when I saw the reply in my "chatterbox", it didn't link to my article, but to a node "XS" (a Super Search link). I think that might be a bug?
      jdporter or someone . . .

      I can see now that we need a "mentions" notification feature. :-/

        Yes and no.

        Mentions notifications would be nice!

        But bug reports should be collected in Perl Monks Discussion

        For instance I knew you patched the length after our discussion.

        But I wasn't easily able to find neither discussion nor patch.

        Ikegami did the right thing.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

        The reply I saw had a SQBRid:// link, but the inner SQBRXS "won", so I hope it's solved properly with that second go.
        Test bug anonymously by lanx
        Test after patch committed by lanx