flag.h icon indicating copy to clipboard operation
flag.h copied to clipboard

Add remaining C numeric types; make default values optional; add ability to mark flags as required

Open dyeo opened this issue 4 years ago • 1 comments

Breaks existing API?: Yes (the flag_bool, flag_str, etc. functions have a parameter removed)

flag_[TYPE]_default functions added to allow the user to specify a default value on a flag, by providing its pointer handle. Similar functionality for flag_required.

On C11-compatible machines or higher, the flag_default macro is available (supplied via. _Generic), which removes the need to supply a type when setting a default value on a flag.

dyeo avatar Oct 12 '21 03:10 dyeo

The internal value type is 64bits, creating functions for different int types does not change that, instead it bloats the interface without adding functionality. Anyone using this can easily cast to a uint_8 or whatever and set the range for that type. Doubles/floats are different because, like bool and str, the bits themselves are interpreted differently and must be handled differently by the library. (which is worth a pr) using a recast macro is cleaner, but traditionally macros are uppercase to imply the use of a macro and not a function by GTK+ coding convention. (maybe CAST(... ?) the nice thing about keeping flags.h as simple as possible; is that people like you can easily extend for more specific types! (and I applaud your effort) That being said, if I was tsoding, I would not accept this pr. And if I was you, I would split the pr into three: float and double support; extra int type support; and c/c++ versioning support.

arkD avatar Oct 20 '21 20:10 arkD