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:[email protected]


------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to