2017-06-22 13:39 GMT+02:00 Lev Serebryakov <l...@serebryakov.spb.ru>:
> Hello Liu,
>
> Thursday, June 22, 2017, 4:46:33 AM, you wrote:
>
>>>>   So, I need to printf() uint64_t in my project, which is built in strict
>>>> ISO C11 mode and with all warnings enabled.
>>>
>>>>   If I try to use "%llu" I get warning that "unknown conversion type
>>>> character 'l' in format". If I use "%I64u" I get "ISO C does not support
>>>> the 'I64' ms_printf length modifier" warning.
>>>   And, yes, I have _POSIX_C_SOURCE defined on compiler's command line.
>>>
>> In order to get C99 conforming `*printf()` functions you have to
>> `#define __USE_MINGW_ANSI_STDIO 1` before inclusion of any standard
>> headers. One preferable way to achieve that is adding
>> `-D__USE_MINGW_ANSI_STDIO` into your CPPFLAGS.
>  I've started to prepare minimal example for my problem and found one more
> ingridient for my problem:" custom function with  prinrf attribute. These
> defines work for system *printf() family, but not  for custom ones.
>
>  Here is very simple example of exactly my problem:
>
> ==============
> #include <stdio.h>
> #include <stdint.h>
> #include <stdarg.h>
>
> __attribute__ ((format (printf, 1, 2)))
> void myprintf(const char *fmt, ...) {
>   va_list args;
>   va_start(args, fmt);
>   vprintf(fmt, args);
>   va_end(args);
> }
>
> int main(int argc, char *argv[]) {
>   uint64_t i = 10;
>   size_t s = 20;
>   (void)argc; (void)argv;
>   printf("%llu %zu\n", i, s);
>   myprintf("%llu %zu\n", i, s);
>   return 0;
> }
> ==============
> lev@lion MINGW64 ~
> $ gcc -D_POSIX_C_SOURCE=1 test.c
>
> lev@lion MINGW64 ~
> $ ./a.exe
> 10 20
> 10 20
>
> lev@lion MINGW64 ~
> $ gcc -D_POSIX_C_SOURCE=1 -std=c11 -Wall -Wextra -Wpedantic -Wformat=2 
> -Werror test.c
> test.c: In function 'main':
> test.c:17:15: error: unknown conversion type character 'l' in format 
> [-Werror=format=]
>    myprintf("%llu %zu\n", i, s);
>                ^
> test.c:17:19: error: unknown conversion type character 'z' in format 
> [-Werror=format=]
>    myprintf("%llu %zu\n", i, s);
>                    ^
> test.c:17:12: error: too many arguments for format [-Werror=format-extra-args]
>    myprintf("%llu %zu\n", i, s);
>             ^~~~~~~~~~~~
> cc1.exe: all warnings being treated as errors
>
> lev@lion MINGW64 ~
> $
>
>
>
>
> --
> Best regards,
>  Lev                            mailto:l...@serebryakov.spb.ru

Well, your issue is "(format (printf, ... )".  First use __printf, or
even better __printf__.  Nevertheless the printf formatter is
representing the default print-formatter style.  That is obviously on
Windows not the gnu-ish variant.

But you can explicit tell it, that you want to use a different
variant. Eg "__attribute__((__format__ (gnu_printf,..." for gnu-style.
We define for this the helper macros __MINGW_PRINTF_FORMAT, and
__MINGW_SCANF_FORMAT depending on __USE_MINGW_ANSI_STDIO's macro
definition.
By this, you can use instead
__attribute__((__format__(__MINGW_PRINTF_FORMAT, ....".

Hope this helps.

Cheers,
Kai

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to