Can I define an array of structures depending on input?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux