warning:0 flag ignored with precision and '%x' gnu_printf format

c, data-structures, printf, warnings

Solution

The format string `%0.2x` means:

- print an unsigned integer in hex

- print at least two numbers

- pad it from left with zeros

Since the precision defines the minimum number of digits to output, the zero padding will be ignored (from the specification). You can use `%.2x` or `%02x` that will do what you want.

To get

   1
  11
55555

You'd use `%4x`.

  01
  11
 111

would be `%4.2x`

0001
0011
55555

would be `%04x` or `%.4x`.

Note that there is difference when the value is signed. The precision defines the number of digits, meaning the value will occupy one more space for the sign. With minimum output width, sign is already counted:

$ printf "%.5i\n%05i\n" '-11' -11
-00011
-0011

Problem

i am getting the following warning when i compile in C. ``` ../tcpuip/uip_arp.c: In function 'display_arp_table': ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_p rintf format ../tcpuip/uip_arp.c:547: warning: '0' flag ignored with precision and '%x' gnu_printf format ``` the line where the error comes is ``` RELEASE_MSG("MAC: %0.2x.%0.2x.%0.2x.%0.2x.%0.2x.%0.2x ",(unsigned char)tabptr->ethaddr.addr[0],(unsigned char)tabptr->ethaddr.addr[1],(unsigned char)tabptr->ethaddr.addr[2],(unsigned char)tabptr->ethaddr.addr[3],(unsigned char)tabptr->ethaddr.addr[4],(unsigned char)tabptr->ethaddr.addr[5]); ``` tabptr is a pointer of struct arp_entry ``` PACKED struct arp_entry { u16_t ipaddr[2]; struct uip_eth_addr ethaddr; u8_t time; #ifdef _ALIGNED_ u8_t dummy; #endif } ``` and ethadder is a pointer for struct uip_eth_addr ``` PACKED struct uip_eth_addr { u8_t addr[6]; } ; ``` Please if anyone can share some light on this warning. I just know that %0.2x means character as two digit HEX. Help!

Original source