Error: initialization makes pointer out of integer without casting

I am having trouble returning this part of the code:

assgTest2.c: In function 'Integrate':
assgTest2.c:12: warning: initialization makes pointer from integer without a cast
assgTest2.c:15: error: expected ';' before ')' token

I looked around and could not understand the answer to such questions, any help would be appreciated.

1    void SamplePoint(double *point, double *lo, double *hi, int dim)
2    {
3       int i = 0;
4       for (i = 0; i < dim; i++)
5          point[i] = lo[i] + rand() * (hi[i] - lo[i]);
6    }
7
8    double Integrate(double (*f)(double *, int), double *lo, double *hi, int dim, 
9                     double N)
10    {
11       double * point = alloc_vector(dim);
12       double sum = 0.0, sumsq = 0.0;
13
14       int i = 0;
15       for (i = 0.0, i < N; i++)
16       {
17         SamplePoint(point, lo, hi, dim);
18
19         double fx = f(point, dim);
20         sum += fx;
21         sumsq += fx * fx;
22       }
23
24       double volume = 1.0;
25       i = 0;
26       for (i = 0; i < dim; i++)
27         volume *= (hi[i] - lo[i]);
28
29       free_vector(point, dim);
30       return volume * sum / N;
31    }

Edit: Fixed some bugs still giving the same error

+4
source share
1 answer

I guess this is your line 12

    double * point = alloc_vector(dim);

Warning text

warning: initialization makes pointer from integer without a cast

This means that the integer returned from alloc_vector()is automatically converted to a pointer, and you should not do this (nor should you throw, despite the warning prompts).

: #include, alloc_vector() , , , (), .

, include, .

double *alloc_vector(int); // just guessing

15

     for (i = 0.0, i < N; i++)

:

assgTest2.c:15: error: expected ';' before ')' token

for ( ). 1 .

     for (i = 0.0; i < N; i++)
     //          ^ <-- semicolon
+6

Source: https://habr.com/ru/post/1531901/


All Articles