Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Implementing `flag_count` and `flag_get`

Đang mở
#16 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
c
Lĩnh vực
cli

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
C
Star
295
Fork
20
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tsoding/flag.h

Tất cả issue của tsoding/flag.h

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.