Search code examples
c

a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x


I was implementing linked list in C program worked but gave the following warnings in terminal

linkedstr.c:36:11: warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    link *search_link() , *pred_link();
          ^
linkedstr.c:36:28: warning: a function declaration without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
    link *search_link() , *pred_link();

here is the code of the following functions

link *search_link(link *l, int x)
{
    if (l == NULL)
        return NULL; //end of list is reached
    if (l->val == x)
        return l;
    else
        return (search_link(l->next, x)); //search sub_list
}

link *pred_link(link *l, int x)
{
    if (l == NULL || l->next == NULL)
        return (NULL);
    if ((l->next)->val == x)
        return (l);
    else
        return (pred_link(l->next, x));
}

I googled and there was an explanation link] but it says that we can't leave parameters empty and we foo(void) must be passed instead of foo() but I clearly gave the parameters in my functions so why the warnings?


Solution

  • The link talks about "function declaration without a prototype", which are these

     link *search_link() , *pred_link();
    

    Once upon a time you could leave () empty, and the compiler would have to kind of guess what parameters the functions use.

    This has been "bad" for a very long time, and will soon be forbidden in C23 (like the compiler says). So just add the parameter types there too, to make them prototypes.