Define variable-length array type for C

Open
#191 6 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
c, python
Domain
backend

Research direction

The issue proposes --no-static-arrays and a user-supplied vector protocol, but names no implementation files or tests. Start by locating the C code-generation templates and deserialization routines, then assess how generated array types are represented. Done would require an agreed design and implementation for variable-length arrays; the issue leaves that design open.

Written by the indexing model from the issue text.

Description

feature

This is a proposal to allow generation of a variable-length array type in C leaving the implementation up to the user.

For example, the standard Quaternion type:


typedef struct
{
    /// saturated float32[4] wxyz
    float wxyz[4];
} uavcan_si_unit_angle_Quaternion_1_0;

when using the proposed language option of `--no-static-arrays' could be generated like this:

typedef struct
{
    /// saturated float32[4] wxyz
    float* wxyz;
    size_t wxyz_len;
} uavcan_si_unit_angle_Quaternion_1_0;

An alternative, that would be more complex but would require less unsafe pointer magic, is to create a Vector protocol. Something like this:

typedef NunavutVectorType_Float
{
    float* data;
    size_t length;
    size_t max_length;
    bool (*resize)(NunavutVectorType_Float*, size_t);
} NunavutVector_Float;

extern NunavutVector_Float* init_nunavut_vector_float(NunavutVector_Float*);

NunavutVector_Float then must be supplied by the user (the linker will enforce this) and the user must provide the resize method which will be called by deserialization routines when Nunavut needs more memory.

This is a half-baked proposal to encourage a discussion. Please comment.

Dominant language
Python
Stars
48
Forks
26
Avg merge
1d 18h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenCyphal/nunavut

All issues in OpenCyphal/nunavut

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.