Following piece of my code does not print the value in visual studio.
int main() {
intptr_t P = 10;
printf("test value is %zd",P);
return 0;
}
OUTPUT:
test value is zd
I expect the the above code print
test value is 10
i am using intptr_t instead of integer so as to make the code to adjust in both the 32 bit and 64 bit architecture.
rL295112: Use "%zd" format specifier for printing number of testcases executed. This helps to avoid signed integer overflow after running a fast fuzz target for several hours, e.g.: <...>
printf with a "%zd" format expects an argument of the signed type that corresponds to the unsigned type size_t . Standard C doesn't provide a name for this type or a good way to determine what it is.
The correct way to print size_t variables is use of “%zu”. In “%zu” format, z is a length modifier and u stand for unsigned type. The following is an example to print size_t variable.
The Printf module API details the type conversion flags, among them: %B: convert a boolean argument to the string true or false %b: convert a boolean argument (deprecated; do not use in new programs).
The z
prefix isn't defined in Microsoft's version of printf
. I think the I
prefix might work. See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx
Although the z
length specifier is supported in C99, Visual Studio 2010 does not support C99, and instead conforms to an older version of C that was missing the z
length specifier. As an extension, VS2010 does support the I
length specifier instead for size_t
, but this is not portable to other platforms.
I would recommend using an unsigned long long
with the %llu
specifier instead; the overhead is minimal and it's portable to C99 platforms as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With