Skip to content
  • Radim Krčmář's avatar
    libcflat: support # flag in printf · c9af8739
    Radim Krčmář authored
    
    
    The only use is with %#x, where we'll automatically get 0x prefix.
    Advantage over 0x%x can be seen with padding.
    
    A simple test:
    
      printf(".%#08x.\n", 0);
      printf(".%#8x.\n",  0);
      printf(".%#-8x.\n", 0);
    
      printf(".%#08x.\n", 1);
      printf(".%#8x.\n",  1);
      printf(".%#-8x.\n", 1);
    
      printf(".%#08x.\n", 0x123456);
      printf(".%#8x.\n",  0x123456);
      printf(".%#-8x.\n", 0x123456);
    
      printf(".%#02x.\n", 0);
      printf(".%#2x.\n",  0);
      printf(".%#-2x.\n", 0);
    
      printf(".%#02x.\n", 1);
      printf(".%#2x.\n",  1);
      printf(".%#-2x.\n", 1);
    
    looks just like glibc:
    
      .00000000.
      .       0.
      .0       .
      .0x000001.
      .     0x1.
      .0x1     .
      .0x123456.
      .0x123456.
      .0x123456.
      .00.
      . 0.
      .0 .
      .0x1.
      .0x1.
      .0x1.
    
    Signed-off-by: default avatarRadim Krčmář <rkrcmar@redhat.com>
    c9af8739