NordicSemiconductor / zcbor

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

dealing with array vs occurrence #358

Closed lucsegers closed 4 months ago

lucsegers commented 10 months ago

ZCBOR seems to be translating following in a different way. How it deals with arrays seems to be wrong:

subvector = [
    name: tstr,
]

vector = [
    item1:    uint.size 4,
    item2:    uint.size 4,
    name1:   [0*32 subvector],
    0*32 name2:   subvector,
]

will be translated to following code:

struct vector {
    uint32_t item1;
    uint32_t item2;
    struct zcbor_string _subvector[32];
    size_t _subvector_count;
    struct zcbor_string name2[32];
    size_t name2_count;
};

as you can see for the array it uses the name of the struct (subvector) with an underscore instead of the name of the field (name1). For the occurrence it uses the name of the field (name2).

For the array, in my opinion, this is wrong. Because this will not scale:

subvector = [
    name: tstr,
]

vector = [
    item1:    uint.size 4,
    item2:    uint.size 4,
    name1:   [0*32 subvector],
    name3:   [0*32 subvector],
]

will be translated by the python script into:

struct vector {
    uint32_t item1;
    uint32_t item2;
    struct zcbor_string _subvector[32];
    size_t _subvector_count;
    struct zcbor_string _subvector[32];
    size_t _subvector_count;
};

which will not compile since both have the same names now

oyvindronningstad commented 10 months ago

Hi, I'm assuming you are using --short-names. See #350

lucsegers commented 10 months ago

I am indeed using --short-names. Still feels a bit wrong though...