Using 'hhx' conversion in sscanf in c99 mode

Edward Diener eldlistmailingz@tropicsoft.com
Sun Dec 3 23:53:00 GMT 2017


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 ?





More information about the Gcc-help mailing list