Help with error "no known conversion from 'double' to 'double (*)(double)" when converting ?

Hi, I want to print looping value from a function in terminal. I have a conversion function, here :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  void spectrum_to_xyz(double (*spec_intens)(double wavelength),
                     double *x, double *y, double *z)
{
    int i;
    double lambda, X = 0, Y = 0, Z = 0, XYZ;
    
    static double cie_colour_match[81][3] = {
        {0.0014,0.0000,0.0065}, {0.0022,0.0001,0.0105}, {0.0042,0.0001,0.0201},
        //... bunch of lines
    };
    
    for (i = 0, lambda = 380; lambda < 780.1; i++, lambda += 5) {
        double Me;
        
        Me = (*spec_intens)(lambda);
        X += Me * cie_colour_match[i][0];
        Y += Me * cie_colour_match[i][1];
        Z += Me * cie_colour_match[i][2];
    }
    XYZ = (X + Y + Z);
    *x = X / XYZ;
    *y = Y / XYZ;
    *z = Z / XYZ;
}


I want to print the value in my terminal and here's how I call it in main :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    double wavelength, x, y, z, r, g, b;
    
    printf("Wavelength       x      y      z       R     G     B\n");
    printf("-----------    ------ ------ ------   ----- ----- -----\n");

    for (wave = 380; wave <= 780; wave += 5)
    {
        double wave;
        spectrum_to_xyz(wave, &x, &y, &z);
        xyz_to_rgb(cs, x, y, z, &r, &g, &b);
        printf("  %5.0f nm      %.4f %.4f %.4f   ", wave, x, y, z);
        if (constrain_rgb(&r, &g, &b)) {
            norm_rgb(&r, &g, &b);
            printf("%.3f %.3f %.3f (Approximation)\n", r, g, b);
        } else {
            norm_rgb(&r, &g, &b);
            printf("%.3f %.3f %.3f\n", r, g, b);
        }
    }
    
    return 0;


But I encountered error :
1
2
3
4
spectrum_to_xyz(wavelength, &x, &y, &z);
        ^~~~~~~~~~~~~~~
no known conversion from 'double' to 'double (*)(double)' for 1st argument
void spectrum_to_xyz(double (*spec_intens)(double wavelength),

I am aware it's the error from converting double to *double, I tried to fix it but still fail. I just want to print the value, any advice ?
Last edited on
The first argument is supposed to be a function but instead you are passing a variable of type double.
Two problems:

1) function line 1: Why are you declaring the first argument to spectrum_to_xyz as double (*spec_intens)(double wavelength) when you're passing a simple double.

2) main line 8: This declaration of wave hides the value used on line 6.
Last edited on
The loop is working now, but the value seems wrong.
here's screenshot : https://i.imgur.com/EP20PZK.png

Is there any way to print value from the function ? I almost believe usual for-loop will work. Now I'm confused.
Last edited on
Please post your revised code. Below.
Topic archived. No new replies allowed.