Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit declaration of function is invalid in C99

Tags:

arrays

c

I am new to C language and I am having a problem that I really don't understand. I am trying to get an array from another function but when I try to extract the information, it gives me the following warning:

Implicit declaration of function 'getk_vector_calculation' is invalid in C99 Array initializer must be an initializer list or string literal

Here is the code:

int k_vector_calculation(int krec[3])

{
    ...

    krec [0] = l*u[0]+m*v[0]+o*[0] ;

    krec [1] = l*u[1]+m*v[1]+o*[1] ;

    krec [2] = l*u[2]+m*v[2]+o*[2] ;

    return k_vector_calculation( &krec[3] ) 

}

int main ()

{

    char krec[3] = getk_vector_calculation(&krec[3]); 

    ...

}
like image 395
B.T. Avatar asked Oct 15 '25 08:10

B.T.


1 Answers

in your main() the function you called is getk_vector_calculation() [which is not k_vector_calculation()] and which is not declared or defined before the usage.

To resolve this,

  1. either #include the header file containg the declaration of getk_vector_calculation() in your sorce file. [Considering getk_vector_calculation() is in some other file]
  2. or, add a forward declaration of getk_vector_calculation() before main() and define getk_vector_calculation() somewhere.

To know more about implicit declaration, you can check this question.


EDIT:

As others have pointed out, there are many more problems in your code snippet. But since the question title is limited to implicit declaration error, IMO, this answer should do the needful. The remaining error(s) is(are) altogether a different aspect.

like image 92
Sourav Ghosh Avatar answered Oct 17 '25 00:10

Sourav Ghosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!