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

3

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

It's weird. What does sharp mean?

Lynellelynett answered 20/8, 2010 at 9:50 Comment(0)
R
8

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.

Ruano answered 20/8, 2010 at 9:54 Comment(0)
A
4

# indcates an alternative format. For x this means that 0x is prepended to the output.

Arachnoid answered 20/8, 2010 at 9:51 Comment(0)
B
3

printf when used with specifier x, # causes the output to be prefixed with 0x provided the value being printed is other than 0.

Boxfish answered 20/8, 2010 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.