c++ - Declaring a union pointer with a pointer inside -
i'm trying learn sse instructions , aspire multiply 2 matices. however, when try initialize 1 of them, program crashes
access violation when typing in location
here's code throws error:
typedef union{ __m128 vec; float* afloat; }u_float; int main(){ __declspec(align(16)) u_float *mat1; mat1 = (u_float*)malloc(sizeof(u_float)*4); for(int = 0; < 4; i++) mat1[i].afloat = (float*)malloc(sizeof(float)*4); for(int = 0; < 4; i++) for(int j = 0; < 4; j++) mat1[i].afloat[j] = 1; // error. return 0;}
- why throwing error?
- and best way resolve problem?
this has nothing union
s. have typo in loop:
for(int = 0; < 4; i++) for(int j = 0; < 4; j++) // <-- here mat1[i].afloat[j] = 1;
notice inner loop loops while i less 4, not when j less 4, loops infinitely.
Comments
Post a Comment