File: array_in_variant.c

package info (click to toggle)
datatype99 1.6.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: ansic: 1,071; sh: 43; makefile: 6
file content (21 lines) | stat: -rw-r--r-- 390 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <datatype99.h>

// Your array must be put into a structure because value constructors, which are ordinary C
// functions, cannot accept an array.
typedef struct {
    int data[5];
} MyArray;

// clang-format off
datatype(
    Foo,
    (MkFoo, MyArray)
);
// clang-format on

int main(void) {
    Foo foo = MkFoo((MyArray){.data = {1, 2, 3, 4, 5}});
    (void)foo;

    return 0;
}