在 2018/10/27 19:52, Jacek Caban 写道:
> I don't see what makes __USE_MINGW_ANSI_STDIO a correct solution.
> Firefox builds use ucrt, which is sufficient for handling stdio (and
> official winapi+clang-cl builds use that anyway).
> 

Oh I didn't know that had migrated to UCRT.

> I took a look at this and I think we want a more radical solution. Right
> now we have _mingw_print_push.h/_mingw_print_pop.h hack that has no
> clean purpose to me. I did some git history checking and when it was
> introduced, it was important for __USE_MINGW_ANSI_STDIO because that was
> where printf/scanf functions were #defined. It was later removed and the
> only thing that's left there is a bunch of PRI* macros. Instead of
> defining and redefining them, we may just as well define them correctly
> in the first place.
> 
> That's what the attached patch does. It also uses the same for ucrt and
> mingw stdio, leaving hackish values only for affected builds. This fixes
> Firefox issue and makes mingw stdio cleaner. It's not yet tested, I'm
> mostly sending it for comments now.
> 

Yes those macros `scanf()` and `printf()` etc. were removed in
d4e56ae45d4f92598f7b393340efca93f3deff38 and now those functions are
implemented by conditional inline definitions. If no other inline
functions [1] in our headers rely on the old format specifiers, the
header <_mingw_print_push.h> is consequenctly unneeded thereafter.

The circumstances of <_mingw_print_pop.h> are a bit more complex. It has
to restore `PRId64` etc. to the correct strings that correspond to what
`printf()` etc., after the inclusion of <inttypes.h>, will eventually
call. Thus at the moment <_mingw_print_pop.h> actually checks for
inclusion of <stdio.h> or <wchar.h> (there was an old thread about this
[2]), otherwise the following code may not produce the expected result:

```c
#define __USE_MINGW_ANSI_STDIO  1
#include <inttypes.h>
#include <stdint.h>

// `PRIx64` is defined as `I64x` here, which will co-operate with
// `printf()` from MSVCRT rather than the inline one in <stdio.h>.
extern int printf(const char *, ...);

int main(void)
  {
    uint64_t value = 0x123456789abcdef0;
    printf("value = %" PRIx64 "\n", value);
  }
```



[1] The functions in <strsafe.h> concerned me. Now I believe they don't
suffer from this change as they only ever call Microsoft variants whose
names begin with an underscore e.g. `_vsnprintf()`.
[2]
https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/1471206950.20170625161106%40serebryakov.spb.ru/#msg35911673

-- 
Best regards,
LH_Mouse

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to