to the top
close form
To get a trial key
fill out the form below
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement

close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS-Studio license for Microsoft MVP specialists
** By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
** By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
** By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
Working with the type size_t in the fun…

Working with the type size_t in the functions prinft, scanf and similar functions

Apr 05 2013
Author:

To work with size_t, ptrdiff_t, intptr_t and uintptr_t types in the functions like sscanf, printf you may use size specifiers. If you are developing a Windows-application, you may use the size specifier "I".

For example:

size_t s = 1; 
printf("%Iu", s);

If you are developing a Linux-application, you may use the size specifier "z". For example:

ptrdiff_t s = 1;
printf("%zd", s);

Specifiers are well described in the Wikipedia article "printf".

If you have to maintain the code being ported that supports functions like sscanf, you may use special macros opening into the necessary size specifiers in the format of the command strings. Here is an example of a macro that helps you create ported code for various systems:

// PR_SIZET on Win64 = "I"
// PR_SIZET on Win32 = ""
// PR_SIZET on Linux64 = "z"
// ...
size_t u;
scanf("%" PR_SIZET "u", &u);
printf("%" PR_SIZET "x", u);

References

Comments (0)

Next comments next comments
close comment form
Unicorn with delicious cookie
Our website uses cookies to enhance your browsing experience.
Accept