Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: [XS] : "snprintf" portability options

by tonyc (Friar)
on Sep 16, 2024 at 22:56 UTC ( [id://11161780]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^5: [XS] : "snprintf" portability options
by NERDVANA (Curate) on Sep 17, 2024 at 01:34 UTC
    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.

        If I could be sure old MSVCRT supported "%llu" I'd make a PR switching it to the standard form

        Would it be feasible to allow for both models in the source, and then base the decision on which model to implement by information gathered during the early stages of the gmake/nmake stage ?
        For example, would the fact that the toolchain uses UCRT alone imply that "%llu" is supported ?
        Or could a "configure" type C script be run to probe whether "%llu" is supported ?

        Cheers,
        Rob
Re^5: [XS] : "snprintf" portability options
by ikegami (Patriarch) on Sep 17, 2024 at 10:25 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11161780]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-10-09 01:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (44 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.