Hasty Briefsbeta

Bilingual

Getopt() but Friendlier

4 hours ago
  • The article proposes a friendlier CLI argument parser in C that improves upon POSIX getopt() by allowing flags before or after positional arguments, using consistent separators for long options, and supporting short option chaining.
  • The author implements an iterator-based parser using a struct to hold state (avoiding global variables) and a tagged union for argument types, achieving re-entrancy and a simpler loop structure.
  • The parser is provided as a C23 single-header library with macros for convenient argument matching (e.g., ARG_SHORT, ARG_LONG, ARG_POS) and error handling.
  • The discussion reflects on C's poor ergonomics and the value of reexamining established conventions, with the author noting C as a 'comfort language' despite its flaws.

Related

Loading…