This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Can I define an array of structures depending on input?
- From: Anna Sidera <sidera dot anna at ucy dot ac dot cy>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 29 Jan 2011 13:26:46 +0200
- Subject: Can I define an array of structures depending on input?
Hello,
I have a program that uses some input parameters. One of these parameters, for example my_input_parameter, takes values 1, 2, 3 and 4. I want to define an array in which each element is a structure. But I want the structure to depend on the value of my_input_parameter. For example:
struct my_structure {
<things that depend on the value of my_input_parameter>
};
struct my_structure *my_array = (struct my_structure *)malloc(10000*sizeof(struct my_structure));
Can you tell me any way to do this?
Below I am explaining the reason I want to do this. My program currently uses many one dimensional arrays. For example buffer1, buffer2, buffer3, .... When the program needs to use the ith element of one of these arrays, usually, it also needs to use the ith element of some others of these arrays. I want to make my program faster. I want to try to store the data in such a way that data that are accessed together are physically near. However for some values of my_input_parameter some of these one dimensional arrays are not used at all. So I want my_stucture to depend on my_input_parameter.
Thanks,
anna