Re: Using 'hhx' conversion in sscanf in c99 mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 04/12/2017 00:53, Edward Diener wrote:

> In the following program, test_scanf_hex.c
> 
> #include <stdio.h>
> int main()
>      {
> 
>      const char * str = "0xa4";
>      unsigned char res = 0;
> 
>      sscanf(str,"%hhx",&res);
> 
>      return (res == 0 ? 1 : 0);
>      }
> 
> If I compile with -std=c99 I receive:
> 
> test_scanf_hex.c: In function 'main':
> test_scanf_hex.c:9:19: warning: unknown conversion type character 'h' in format [-Wformat=]
>       sscanf(str,"%hhx",&res);
>                     ^
> test_scanf_hex.c:9:16: warning: too many arguments for format [-Wformat-extra-args]
>       sscanf(str,"%hhx",&res);
>                  ^~~~~~
> test_scanf_hex.c:9:19: warning: unknown conversion type character 'h' in format [-Wformat=]
>       sscanf(str,"%hhx",&res);
>                     ^
> test_scanf_hex.c:9:16: warning: too many arguments for format [-Wformat-extra-args]
>       sscanf(str,"%hhx",&res);
>                  ^~~~~~
> 
> Why is the 'hh' modifier not supported in c99 ?

I cannot reproduce this issue.

$ cat scanf.c
#include <stdio.h>
int main(int argc, char **argv)
{
     unsigned char res;
     if (argc > 1)
	     sscanf(argv[1], "%hhx", &res);
     return res;
}

$ gcc-4.8 -std=c99 -O2 -Wall -Wextra scanf.c && ./a.out 10 ; echo $?
16
$ gcc-5 -std=c99 -O2 -Wall -Wextra scanf.c && ./a.out 10 ; echo $?
16
$ gcc-6 -std=c99 -O2 -Wall -Wextra scanf.c && ./a.out 10 ; echo $?
16
$ gcc-7 -std=c99 -O2 -Wall -Wextra scanf.c && ./a.out 10 ; echo $?
16


I suspect you are using a Windows port, such as mingw?

Regards.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux