there are a lot of explanations about these things, but I cannot seem to get the basic concepts with variables between .h and .c files. I cannot change the layout, so to speak, of the files and their contents. Here is my code:
driver.h
#ifndef VARIABLES_H
#define VARIABLES_H
//size limits for Pk
double limit_x;
double limit_y;
double limit_z;
//grid cells
int cells_x = 500;
int cells_y = 500;
int cells_z = 500;
extern double particles[][3];
extern double randMtoN();
extern int populateParticles();
#endif
driver.c
#include "driver.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main(int argc, char **argv) {
//seed rand()
srand((unsigned)time(NULL));
//add particles to box
limit_x = 200;
limit_y = 200;
limit_z = 200;
int particle_no = 10000;
double particles[particle_no][3];
//memset(particles, 0, sizeof particles);
populateParticles(limit_x, limit_y, limit_z, particle_no, particles);
printf("l\n");
printf("%d %f %f %f", 1, particles[0][0], particles[0][1], particles[0][2]);
}
functions.c:
double randMtoN(double M, double N) {
return M + (rand() * N);
}
int populateParticles(double limit_x, double limit_y, double limit_z, int particle_no, double **particles) {
//double particles[particle_no][3];
for (int i = 0; i < particle_no; i++) {
particles[i][0] = randMtoN(0, limit_x);
particles[i][1] = randMtoN(0, limit_y);
particles[i][2] = randMtoN(0, limit_z);
}
return 0;
}
What I get is this warning: implicit declaration of function ‘rand’ [-Wimplicit-function-declaration] return M + (rand() * N);
And then a segfault (due to the particles[][] in functions.c)