0

I want to convert this piece of code using this memory layout transformation : https://software.intel.com/en-us/articles/memory-layout-transformations (Array of Structures to Structure of Arrays)
Here are the codes before and after applying the transformation and I want to know whether I'm doing it right or not?

Before:

typedef struct {
  double x;
}str1;

typedef struct {
  str1 v;
}str2;

int main(){

str2 *pointer;

double y = pointer[1].v.x;

return 0;
}

After:

typedef struct {
  double x[1];
}str1;

typedef struct {
  str1 v;
}str2;

int main(){

str2 pointer;

double y = pointer.v.x[1];

return 0;
}

Edited by hg_fs2002

2
Contributors
3
Replies
20
Views
3 Years
Discussion Span
Last Post by Hiroshe
0

Thanks, I fixed the typo's. Is it still correct if instead of double x[1], I use double *x ?

0

Well, you'll need to point *xto somwhere to use it, since it's not allocated for you,

For example: x = (double *)malloc(ARRAY_SIZE*sizeof(double));. Remember to free heap allocated memory when you're done with it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.