Press enter to see results or esc to cancel.


note: previous implicit declaration of ‘point_forward’ was here [SOLVED]


In this video I have shown how you can solve ‘note: previous implicit declaration of ‘point_forward’ was here’
Also the issue ‘incompatible types when assigning to type’.

As shown in the video, The error was thrown on compiling the code.


#include "stdio.h"
struct mystruct
{
int item1;
int item2;
};
void main()
{
struct mystruct  myvar;
myvar = fun();
}
struct mystruct fun()
{
struct mystruct local_var;
printf("%s:%d \n", __FUNCTION__, __LINE__);
return local_var;
}

Below screen shot shows the execution.

The above 2 errors are thrown when implicit declaration mismatches with real definition of the function. In the above code, in line:12, compiler assumes the fun() as a function that returns integer (this is called implicit declaration. Implicit declaration will always have integer as return type). At line:12 itself, data type on left hand side vs datatype on right hand side is mismatching. Hence “error: incompatible types when assigning to type” is thrown.

Another error will be thrown when real definition of fun() is encountered at line:15. It finds the return value as not integer which is contradicting with implicit declaration made at line:12. Hence “note: previous implicit declaration of ‘fun’ was here” is thrown.

Solution

Always have explicit declaration of new functions before it is called. Just add “struct mystruct fun();” before line:12.


Comments

Leave a Comment