cfunctiondebugging

Function that has parameters as pointers is not working when I take in addresses of variables


The code here is for filtering an image
        //variables for purpose of shortening some lines
        int b = image[i][j].rgbtBlue;
        int g = image[i][j].rgbtGreen;
        int r = image[i][j].rgbtRed;

        int bound = 255;

        //variables here are for rounding purposes
        float Sb = .272 * r + .534 * g + .131 * b;
        int tempSb = .272 * r + .534 * g + .131 * b;
        
        //rounding to nearest integer
        if (Sb != tempSb && Sb >= tempSb + 0.5)
        {
            tempSb++;
        }
        //checking if that rounded integer is higher than bound (and if so set it to bound)
        void nohigherthan_int(&bound, &tempSb);
        //setting the correct pixel to sepia blue
        image[i][j].rgbtBlue = tempSb;


        void nohigherthan_int(int *a, int *b)
        {
            if (*a <= *b)
            {
                *b = *a;
            }
        }

and this code is for the function I am struggling with since the terminal is saying ,firstly
"expected parameter declarator" pointing to &bound (i.e the address for the bound variable) and secondly that the prototype I have put doesn't match the function (aka it is saying a function declaration without a prototype is deprecated in all versions of c, conflicting with a previous declaration then pointing to my prototype and the function in which I put the variable &bound, &tempSb the function prototype is just a copy paste of the function I declared above (which I put above the rest of the code)

I have tried to change the values to int *a = &bound and int *b = &tempSb and the errors did go away but default arguments aren't supported.


Solution

  • void nohigherthan_int(&bound, &tempSb);
    

    This line is a problem and more precisely void. Remove void and it will compile OK

    When you have void at the beginning the compiler treats it as declaration (and it has the wrong syntax in this case), not a function call.

    Also, remember to have a function prototype before the first call.

    void nohigherthan_int(int *a, int *b);