Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Printing size_t correctly #10

Closed
UnitedMarsupials-zz opened this issue Jul 15, 2016 · 1 comment
Closed

Printing size_t correctly #10

UnitedMarsupials-zz opened this issue Jul 15, 2016 · 1 comment

Comments

@UnitedMarsupials-zz
Copy link
Contributor

Throughout the code variables of type size_t are printed as long (%ld). This is incorrect in two ways:

  • long is signed, whereas size_t is not
  • long may not be the same width as size_t -- in particular, on i386 (32-bit) systems long is usually a 64-bit integer, while size_t is 32 bit

The correct format specification for size_t is %zu. For ssize_t it is %zd. Pull requests are messy, so I'll just leave an old-fashioned patch-file here. Please, merge it in. Thank you!

patch-warnings

@danielrh
Copy link
Contributor

Hmm... is %zu standard on all compilers--even weird ones like MSVC?
http://stackoverflow.com/questions/15610053/correct-printf-format-specifier-for-size-t-zu-or-iu
it seems not...
I just casted them to longs and used %lu for now

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants