The issue I'm running into is defining the arguments of a function where the data structure is defined in a different file. In the main file I define the arrays nPart[3]={a,b,c};
and particle p[np];
where a,b,c,np
are integers. I then define the array:
particle *pp[ nPart[0] ][ nPart[1] ][ nPart[2] ][ np ];
which points to different particles in the p
array.
In a second file I want to create a function:
void function(int np, particle *p, particle *pp[ nPart[0] ][ nPart[1] ][ nPart[2] ][ np ]){...}
however since I have defined nPart
in the first file I'm unsure how I should do this. The second file's .h file is included in the first document.
I feel like I should somehow pass nPart
as an argument to the function, along with some information about the location of pp
and then be able to construct pp
inside the function however I'm pretty lost as to how I should go about this.
EDIT: My lack of knowledge of terminology and C in general is probably making this more confusing that it should be.
I'll try to make a simple example:
In the first file's main function I define:
int x[3] = {1,2,2};
int *p[ x[0] ][ x[1] ][ x[2] ];
Then in the second file I want to be able to be able to use *p
as an argument to functions. However, since x
is defined locally in the main function I'm unsure how to do this.
The reason I'm trying to define *p
in terms of x
is that there are other things which also depend on x
and so I want to be able to adjust just x
rather than manually changing everything.
EDIT 2:
It seems that by switching the order of the arguments in my original code with nPart
before *pp
I am able to do what I wanted to do.
see relemos' answer here: Passing multidimensional arrays as function arguments in C
I guess I just wasn't searching with the right terminology the first time I looked for answers.