Here is one way to solve this:
typedef struct
{
int currentindex;
int array[0];
}
tempstruct;
int main()
{
...
int totalSize = sizeof(tempstruct) + sizeof(int) * numOfElements;
ptr = mmap(0, totalSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
...
}
Please note that you will not be able to properly utilize an array of tempstruct
instances.