Project ideas from Hacker News discussions.

C's Flexible Integer Sizes Were Not a Design Mistake

📝 Discussion Summary (Click to expand)

Three prevalent themes in the discussion

  1. Historical flexibility was essential for C’s portability and survival
  2. “C would probably not have survived unless it had this flexibility.” — quelsolaar
  3. “The C flexible integer sizes were still necessary at the time of its creation, when some important computers still had word sizes that were not powers of two.” — adrian_b
  4. Many argued that C’s ability to map int, long, etc. to the natural word size of wildly different architectures (from 16‑bit microcontrollers to 36‑bit mainframes) was a key reason it could be used everywhere.

  5. Flexible sizes create portability, correctness, and ABI problems; fixed‑width types are preferable

  6. “On modern computers, it is impossible to write correct C programs that are agnostic about the true size in bits of the ‘flexible’ types… those assumptions must be made explicit, by using types like int16_t, int32_t etc.” — adrian_b
  7. “For actually portable C code it was always better to use fixed-width integer types which were chosen for the problem to solve instead of target hardware capabilities.” — flohofwoe
  8. Commenters highlighted issues like unexpected overflows, mismatched size_t/pointer sizes, ABI mismatches, and the proliferation of #ifdef spaghetti when mixing traditional and fixed‑size types.

  9. Performance and backward compatibility justify keeping common types (like int) 32‑bit even on 64‑bit systems, and using the fast/least variants when needed

  10. “int being 32‑bits on amd64 was the correct decision… Existing 32‑bit code just worked on the 64‑bit chip… compilers will emit 32‑bit versions of instructions when the upper 32‑bits are not needed, because it’s cheaper.” — sparkie
  11. “On a modern computer, the ideal integer type is usually smaller than 64 bits… 64 bits take up twice the memory bandwidth, and half as many fits in a cache‑line.” — quelsolaar
  12. Several noted that using int_fastN_t/int_leastN_t lets programmers express performance or storage requirements without tying themselves to the hardware’s word size.

🚀 Project Ideas

PtrSafeLint

Summary

  • Detects unsafe pointer‑to‑integer (intptr_t/uintptr_t) conversions that can lead to dereference mismatches caused by segmentation, thread‑local storage, or capability bits.
  • Core value: Prevent subtle bugs where two pointers compare equal but dereference to different addresses.

Details

Key Value
Target Audience Systems programmers, embedded developers, security‑focused C/C++ engineers
Core Feature Static analysis (Clang‑tidy check or LLVM pass) that flags pointer‑to‑intptr_t casts followed by a dereference, with special handling for thread_local and segmented models
Tech Stack Clang/LibTooling, Python wrapper, optional Docker CI integration
Difficulty Medium
Monetization Revenue-ready: SaaS tier ($10/mo per private repo), free for open‑source

Notes

  • HN user sparkie warned: “two pointers can compare equal but point to different addresses, thus it's not necessarily a safe operation to dereference a pointer cast from intptr_t.”
  • tialaramex noted capability bits in pointers (CHERI) make plain integer conversion unsafe.
  • Potential for discussion: integrating PtrSafeLint into CI pipelines could catch ABI‑breaking pointer casts early, sparking conversations about safer low‑level interop.

CTypeGen

Summary

  • Generates a custom header with exact‑width typedefs and compile‑time bit‑width constants for any target compiler/architecture, eliminating #ifdef spaghetti.
  • Core value: Write portable C using familiar type names (int, long) while guaranteeing known sizes, reducing reliance on manual stdint.h tricks.

Details

Key Value
Target Audience Library maintainers, cross‑platform developers, embedded engineers working on exotic ISAs (DSPs, 24‑bit chars, etc.)
Core Feature Command‑line tool that queries the target compiler (sizeof, _BitInt, limits) and emits a header with types like my_int_t, my_long_t, plus MY_INT_WIDTH, MY_INT_MIN, MY_INT_MAX constants
Tech Stack Clang driver, simple Python/Bash script, output as portable C header
Difficulty Low‑Medium
Monetization Hobby

Notes

  • Commenter adrian_b wished for “another operator or macro to provide the size in bits of any integer type.”
  • quelsolaar highlighted DSPs where char = short = int = 24 bits, showing the need for architecture‑aware types.
  • CTypeGen would reduce the pain of manual typedefs and spark discussion about portable integer models in modern C.

ABIguard

Summary

  • Monitors the public C ABI of libraries, detecting changes in integer type sizes, struct layout, and alignment that could break downstream users.
  • Core value: Catch ABI breakage early (e.g., when moving between 32/64‑bit or exotic architectures) before releasing a new version.

Details

Key Value
Target Audience Library maintainers, package distributors, anyone publishing C shared objects or static libs
Core Feature CI step that compiles probe programs on multiple architectures, extracts sizeof/alignof of public types, compares against a baseline, and posts a diff/comment on PRs
Tech Stack Docker/GCC‑Clang, abi-compliance-checker‑like script, GitHub Action or GitLab CI integration
Difficulty Medium
Monetization Revenue-ready: $20/mo per private repository (free tier for public OSS)

Notes

  • InvisibleUp stressed that “the standard way of defining a library ABI is with a C header… everyone has to worry about precisely defining integer sizes.”
  • adrian_b noted that flexible integer sizes cause portability problems unless explicit fixed‑width types are used.
  • ABIguard would give concrete data for discussions about versioning and compatibility, encouraging safer library evolution.

Read Later