Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
Working with the type size_t in the fun…

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

05 Avr 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

Popular related articles

S'abonner

Comments (0)

close comment form
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam