0

At this simple code, I am passing an array of __m256i to a function, and making it new there. However, it has this error :

EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

My code:

#include <iostream>
#include <immintrin.h>

void fun(__m256i **x){
    *x = new __m256i [10];
    (*x)[0] = _mm256_setr_epi64x(1, 2, 3, 4); -----> Error is here
}

int main() {
    __m256i *x;
    fun(&x);
    return 0;
}

Any help will be greatly appreciated.

  • Did you remember to compile with C++17 so `new` will respect alignments greater than `alignof(max_align_t) = 16`? I'm assuming no, otherwise that should work. C++ before C++17 sucks at memory alignment for dynamic allocation with `new`. – Peter Cordes Feb 05 '22 at 19:22
  • @PeterCordes Many thanks for your help. – Mojtaba Valizadeh Feb 05 '22 at 19:33

0 Answers0