[Mingw-w64-public] mingw-w64 and __attribute__((format(printf))) issue

Liu Hao lh_mouse@126.com
Thu May 7 04:09:22 GMT 2020


在 2020/5/6 18:48, Martin Storsjö 写道:
> 
> So something like this should work:
> 
> #ifdef __MINGW32__
> #define PRINTF_FORMAT __MINGW_PRINTF_FORMAT
> #else
> #define PRINTF_FORMAT printf
> #endif
> 
> __attribute__((format(PRINTF_FORMAT)))
> 
> Not very pretty, but should work without hardcoding any assumptions
> about which format actually is used.
> 

This requires `#include <stdio.h>` first.

Also I don't think it is correct to check for `__MINGW32__` for this
purpose, as the original MinGW.org header doesn't seem to provide
`__MINGW_PRINTF_FORMAT` [1].

However a direct check for `__MINGW_PRINTF_FORMAT` should suffice [2].
It is building well now, albeit still with some minor warnings:

```
../../gcc-git/lto-plugin/lto-plugin.c:927:29: note: format string is
defined here
  927 |     sscanf (s, ".%" PRI_LL "x", &obj->out->id);
      |                  ~~~~~~~~~~~^
      |                             |
      |                             unsigned int *
      |                  %" PRI_LL "llx

```


[1]
https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.3-trunk/mingwrt/include/stdio.h
[2]
https://github.com/msys2/MINGW-packages/pull/6453/files#diff-49b46b088a6393d449afcdbfbe4e710e



-- 
Best regards,
LH_Mouse

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20200507/298c7f8a/attachment-0001.sig>


More information about the Gcc-help mailing list