Implementing `flag_count` and `flag_get`
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start with the TODO in example.c and inspect the existing flag API and Flag_Context usage before assessing the proposed flag_count and flag_get functions. Done requires resolving the public Flag_Info shape, value representation, and compatibility implications, which the issue leaves open.
Written by the indexing model from the issue text.
Description
You have the following comment in example.c:
// TODO: Would be nice to have some sort of mechanism to inspect all the defined flags
// Maybe just expose flag_global_context? But I'm afraid that this will make changing
// its internal structure in a backward compatible way more difficult...
// But the only reason we may want to change it right now is to make the array of the
// flags dynamic. Maybe we should just make it dynamic and finally expose the internal
// structure for good?
What about implementing functions flag_count and flag_get(i) as a compromise?
I mean, the API could look like:
size_t flag_count(void);
const Flag_Info *flag_get(size_t index);
where Flag_Info is a structure, something like:
typedef struct {
const char *name;
Flag_Type type;
const char *desc;
const void *value; // or provide a separate function to read the current value
} Flag_Info;
In this case, the Flag_Context stays private, but we can iterate for (size_t i = 0; i < flag_count(); ++i) and collect metadata if needed.
We may also add more fields to Flag_Info, for example, a default value or a field that indicates whether “was this flag provided?”, or something else.
Should I try to implement this?
- Dominant language
- C
- Stars
- 295
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
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.
More from tsoding/flag.h
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
zephyrproject-rtos/zephyr#120318 · 1 comment ·
-
issue: bug report
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
darktable-org/darktable#22386 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100