Search code examples
cformat-string

Do you know about %#x, in C language format string


KdPrint((
         "Unknown IoControlCode %#x\n",
                io_stack->Parameters.DeviceIoControl.IoControlCode
        ));

It's weird. What does sharp mean?


Solution

  • The printf documentation says:

    The character % is followed by zero or more of the following flags:

    # The value should be converted to an ‘‘alternate form’’. For o conversions, the first character of the output string is made zero (by prefixing a 0 if it was not zero already). For x and X conversions, a non-zero result has the string ‘0x’ (or ‘0X’ for X conversions) prepended to it. For a, A, e, E, f, F, g, and G conversions, the result will always contain a decimal point, even if no digits follow it (normally, a decimal point appears in the results of those conversions only if a digit follows). For g and G conversions, trailing zeros are not removed from the result as they would otherwise be. For other conversions, the result is undefined.

    MSDN docs on the flags are here.

    so for %#x the value is simply prefixed with 0x. Where %x would yield 34ab, %#x would yield 0x34ab.