Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Helper macros #32

Open
Open

Description

@ZiGaMi

Add helper macros as proposed by @tripping-code

#define PARAM_DECLARE_TYPE(type, typename)  \
    typedef struct                          \
    {                                       \
        type def;                           \
        type min;                           \
        type max;                           \
    } typename

PARAM_DECLARE_TYPE(uint8_t param_u8_t);
PARAM_DECLARE_TYPE(int8_t param_i8_t);

typedef struct
{
    param_type_t type;
    param_id_t id;
    const char *name;
    param_access_t access;
    bool is_persistent;
    union
    {
        param_u8_t u8;
        param_i8_t i8;
        param_u16_t u16;
        param_i16_t i16;
        param_u32_t u32;
        param_i32_t i32;
        param_f32_t f32;
    } *cfg;
} param_t;

#define PARAM_I8(enum_, id_, name_, def_, min_, max_, access_, is_persistent_)  \
    [enum_] = {                                                                 \
        .type = ePARAM_TYPE_I8,                                                 \
        .id = id_,                                                              \
        .name = name_,                                                          \
        .access = access_,                                                      \
        .is_persistent = is_persistent_,                                        \
        .cfg = &(const param_i8_t){                                             \
            .def = def_,                                                        \
            .min = min_,                                                        \
            .max = max_                                                         \
    }}

// param_cfg.c

const param_t g_param_table[] =
{
    //        id    name    def     min     max     access              is_persistent
    PARAM_I8(100,   "t_i8", -1,     -50,    50,     ePARAM_ACCESS_RW,   false),
    PARAM_F32(100, "t_f32", 0.f     0.f     100.f   ePARAM_ACCESS_RW,   false)
};

Activity

  1. added
    enhancement
    on Feb 26, 2026
  2. self-assigned this
    on Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions