[sprintf] Support for 16-bit int systems

Open
#30 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
c
Domain
backend

Research direction

The size assumptions are in stb_sprintf.h, and the issue points to the length-modifier checks around lines 543-555, where 'z' tests for ptrdiff_t instead of size_t and 'j' tests for size_t instead of intmax_t. Start there and find where sizeof(int) == 4 is assumed. Done means the modifier checks match the C types they name and the int width is taken from the platform, with the change compiling for a 16-bit int target.

Written by the indexing model from the issue text.

Description

The library makes various assumptions about the size of primitive types.
In particular, it assumes that sizeof(int) == 4.
It would be nice to be more standard and respect the actual int size of the system, as well as have better checks for the proper size to use for the 'j' 'z' 't'.
'z' now checks for the wrong type -- prdiff_t rather than size_t; and 'j' checks for 'size_t' rather than 'intmax_t', in order to avoid including more standard headers:
https://github.com/nothings/stb/blob/f0569113c93ad095470c54bf34a17b36646bbbb5/stb_sprintf.h#L543-L555

Dominant language
C
Stars
18
Forks
5
Avg merge
1m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nothings/stb_sprintf

All issues in nothings/stb_sprintf

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.