zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Implement constraints for all array elements

Open mikir opened this issue 2 years ago • 0 comments

Currently, there is not possible to define constraints for all array elements. It is possible to define constraint only for one array element.

The following example shows workaround which can be used in case of any need of constraints for all array elements:

struct NoneZeroElement
{
    int8 element : element != 0
};

struct Test
{
    varsize numElements;
    NoneZeroElement array[numElements];
};

However, such solution is cumbersome and it would be better to support constraints for all array elements directly in language. One possible solution could be by using index operator '@':

struct Test
{
    varsize numElements;
    int8 array[numElements] : array[@] != 0;
};

mikir avatar Feb 10 '23 12:02 mikir