The solution to the Warning prompt in C language programming: warning: implicit declaration of function 'XXX', conflicting types for 'XXX'

       

content   

reason

Solution

Summarize


I encountered an error when writing C language code with codeblocks: implicit declaration of function 'XXX', conflicting types for 'XXX', where 'XXX' represents the function name I named myself. As shown below.

reason:

       This warning occurs because the function B defined after the function A is called in the function A that you wrote, or when you call the function B here, the function B has not been defined before here, after all, the function A major feature of is sequential execution. When you call a function defined later here, the above warning will appear.

Solution:

        The first solution: at the beginning of the program, declare the defined function name. As shown in the figure below, I first defined a function buildHead , and then called head in the function buildHead . Note: my head function is defined after the build function, so we need to declare the head function at the beginning. The red square in the figure below The box is the format of the declaration, and there will be no Warning at this time.

        The second solution, I first define the head function, and then I define the buildHead function. At this time, when I call the head function in the buildHead function , I don't need to declare a function definition at the beginning, that is, no The head function needs to be written in the red box in the above figure , because when I call the head function in the buildHead function , I have already defined the head function in advance. As shown in the figure below, swap the order of the two functions, and there will be no Warning prompt when running.

 Summarize:

       If a function has been defined before the caller, the function can be called directly; if a function has not been defined before the caller, we can first declare the function name at the beginning, so that the function can also be called without A warning appears.

 

Guess you like

Origin blog.csdn.net/BaoITcore/article/details/123507044