NordicSemiconductor / zcbor

Low footprint C/C++ CBOR library and Python tool providing code generation from CDDL descriptions.
Apache License 2.0
119 stars 38 forks source link

[Code generation] math.h not included when float_t is used #134

Closed VeijoPesonen closed 2 years ago

VeijoPesonen commented 3 years ago

floatt is a C99 feature and the code generator doesn't inject include _ to a generated header file when needed.

struct numeric_ {
    union {
        int32_t _numeric_int;
        float_t _numeric_float;
    };
    enum {
        _numeric_int,
        _numeric_float,
    } _numeric_choice;
};

CDDL used

lwm2m_senml = [1* record]

record = {
    ? bn => tstr,        ; Base Name
    ? bt => numeric,     ; Base Time
    ? n => tstr,        ; Name
    ? t => numeric,     ; Time
    ? ( v => numeric // ; Numeric Value
        vs => tstr //   ; String Value
        vb => bool //   ; Boolean Value
        vd => bstr ), ; Data Value
    * key-value-pair
}

; now define the generic versions
key-value-pair = ( label => value )

label = non-b-label / b-label
non-b-label = tstr / uint
b-label = tstr / nint

value = tstr / bstr / numeric / bool

; numeric = number / decfrac
numeric = int / float

bver = -1  n  = 0   s  = 5
bn  = -2   u  = 1   t  = 6
bt  = -3   v  = 2   ut = 7
bu  = -4   vs = 3   vd = 8
bv  = -5   vb = 4
bs  = -6

cddl-gen version

main (fc9b5a6)

oyvindronningstad commented 2 years ago

Float support is being fixed in #159