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;} 
  1. why throwing error?
  2. and best way resolve problem?

this has nothing unions. 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

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -