0

i'm trying to compile c code with c++ compiler written by someone else, always i got this "error: expected primary-expression before ‘.’ token." how to initialize the union in this case? Thanks in advance.

union v16b {
    v16qi v;
    uint8_t b[16];
    uint32_t dw[4];
};

union v8w {
    v8hi v;
    int16_t w[8];
};

union v2qw {
    v2di v;
    uint64_t uq[2];
};

static inline void sd(v16qi a, v16qi b, v16qi c, v16qi d, uint16_t local_mean[4], int16_t *response)
{
    const union v16b zero = { .b = { 0 }};

    const union v16b shuf = { .b = { 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15 }};
......
}
newww0
  • 181
  • 3
  • 12

1 Answers1

4

C++ does not support initialization with designators. So this statement

const union v16b zero = { .b = { 0 }};

has a syntax error in C++.

This syntax is adopted in C. So either compile your program as a C-program or change this definition according to the syntax of C++.

If you need to initialize this data member then write a constructor. For example

union v16b {
    v16b() : b { 0 ) {}
    v16qi v;
    uint8_t b[16];
    uint32_t dw[4];
};
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335