Switching to Fixed-Width Types (stdint.h) for Cross-Platform Safety
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 10
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Since we're supporting everything from 16-bit (c99 for older tools chains) to 32/64-bit chips, using int or long is asking for trouble. Their sizes change depending on the CPU, which breaks our struct layouts and wastes RAM on padding. We should swap out for uint8_t, uint32_t, etc., and uintptr_t is specifically designed to match the pointer width on the target hardware (2 bytes on 16-bit, 4 on 32-bit, etc.).
| Original Type | Fixed-Width Replacement | Size (Bits) | Best Use Case |
|---|---|---|---|
| unsigned char | uint8_t | 8 | Buffers, small IDs, and raw bytes. |
| unsigned short | uint16_t | 16 | 16-bit sensor data and 16-bit registers. |
| unsigned int | uint32_t | 32 | Standard integers, counters, and IPv4. |
| int | int32_t | 32 | Signed math where 32-bit range is needed. |
| unsigned long | uint32_t or uint64_t | 32 or 64 | Danger: Size varies by CPU. Pick a fixed width. |
| void * (as int) | uintptr_t | Variable | Safely storing an address as an integer |
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the repository’s uses of int, long, unsigned char, unsigned short, unsigned int, and pointer-to-integer conversions. Compare each use with the fixed-width replacements listed in the issue, paying particular attention to struct layouts and embedded target widths. Done means the relevant types use appropriate stdint.h definitions without changing required sizes or pointer-width behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100