Can someone please explain these errors? I don't have a multidimensional array so I don't understand how I'm getting this error.

main.c:291: warning: passing argument 2 of ‘type_specifier’ from incompatible pointer type
main.c:263: note: expected ‘int *’ but argument is of type ‘int **’
main.c:291: warning: passing argument 3 of ‘type_specifier’ from incompatible pointer type




void declaration_list(char *strings_line_tokens[], int *big_boy_counter, int *lower_bound_of_big_boy_counter)
{
    int cmp_str1 = 0;
    int cmp_str2 = 0;
    int cmp_str3 = 0;
    printf("declaration_list().\n");
    cmp_str1 = strcmp("int", strings_line_tokens[*lower_bound_of_big_boy_counter]);
    cmp_str2 = strcmp("float", strings_line_tokens[*lower_bound_of_big_boy_counter]);
    cmp_str3 = strcmp("void", strings_line_tokens[*lower_bound_of_big_boy_counter]);
    if(cmp_str1 == 0 || cmp_str2 == 0 || cmp_str3 == 0)
    {
        declaration(strings_line_tokens, &big_boy_counter, &lower_bound_of_big_boy_counter);
    }
    //declaration_prime();
    //declaration_list();
}

void program(char *strings_line_tokens[], int *big_boy_counter, int *lower_bound_of_big_boy_counter)
{
    int cmp_str1 = 0;
    int cmp_str2 = 0;
    int cmp_str3 = 0;
    printf("In program().\n");
    cmp_str1 = strcmp("int", strings_line_tokens[*lower_bound_of_big_boy_counter]);
    cmp_str2 = strcmp("float", strings_line_tokens[*lower_bound_of_big_boy_counter]);
    cmp_str3 = strcmp("void", strings_line_tokens[*lower_bound_of_big_boy_counter]);
    if(cmp_str1 == 0 || cmp_str2 == 0 || cmp_str3 == 0)
    {
        declaration_list(strings_line_tokens, &big_boy_counter, &lower_bound_of_big_boy_counter);
    }
}

Dani AI

Generated

Short answer: the warnings mean you passed an int ** where the function expected an int *. That happens because you took the address (used &) of variables that were already pointers. As explained, program receives big_boy_counter and lower_bound_of_big_boy_counter as int *, so calling another function with &big_boy_counter turns that into int ** and triggers the incompatible-pointer warning.

Most likely fix (and the simplest): stop taking the address when forwarding those pointers. For example, call the helper as
declaration_list(strings_line_tokens, big_boy_counter, lower_bound_of_big_boy_counter) (no &). Likewise, inside declaration_list forward the same pointers to other functions (do not use & there either). To modify the counter value from the callee, dereference it in the callee (e.g. (*big_boy_counter)++).

Alternative approaches:

  • If you truly wanted the callee to be able to reassign the caller’s pointer variable (rare for simple counters), change the parameter type to int ** and adjust dereferences accordingly.
  • If you wanted to pass integers by value instead, change the parameter types to int and pass the integer or *ptr as appropriate.

Extra tips: declare prototypes before use so the compiler can check signatures, and compile with -Wall -Wextra to catch these mismatches early. Also verify lower_bound_of_big_boy_counter points to a valid index before using it to index strings_line_tokens.

program accepts big_boy_counter and lower_bound_of_big_boy_counter as int*. You then pass the address of those to declaration_list, which makes them both int**. But declaration_list also expects int*, which means you're passing a value of incompatible type.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.