(a) First, let’s take a look at an example where the definition and declaration of a function are inconsistent:
#include <stdio.h> int func(int a); int func(void) { return 0; } int main(void) { func(); return 0; }
Compiler:
gcc -g -o a a.c a.c:5:5: error: conflicting types for ‘func’ int func(void) { ^ a.c:3:5: note: previous declaration of ‘func’ was here int func(int a);
You can see that this error occurs at compile time because the declaration and definition of “func” are inconsistent (one with arguments and one without).
(b) Recently, when I ported some code to JFFS2, this error also occurred at compile time. But I found that the declaration and definition of the function in the header file were exactly the same, which surprised me. The conclusion is that the function parameter type is defined after the function is declared. The simplified code is as follows:
#include <stdio.h> void func(struct A *A); struct A { int a; }; void func(struct A *A) { printf("%d", A->a); } int main(void) { // your code goes here struct A a = {4}; func(&a); return 0; }
Where the definition of “structure A” is placed after the “func” function declaration, and the func function argument is the “structure A*” type. The compilation results are as follows:
gcc -g -o a a.c a.c:3:18: warning: ‘struct A’ declared inside parameter list void func(struct A *A); ^ a.c:3:18: warning: its scope is only this definition or declaration, which is probably not what you want a.c:9:6: error: conflicting types for ‘func’ void func(struct A *A) ^ a.c:3:6: note: previous declaration of ‘func’ was here void func(struct A *A); ^
You can also see the output error “error: Conflicting Types for ‘func'”. Perhaps a compilation warning is a clue.
Read More:
- Analysis of the causes of errors in G + + compilation “was not declared in this scope”“
- Idea ignores compilation errors and runs in eclipse compilation mode
- Analysis and solution of common errors in ArcEngine development
- C language write() function analysis: write failed bad address
- Solutions to vs2013 compilation errors
- Solutions to various inexplicable errors after QT compilation
- Some errors in VTK compilation
- tf.layers.conv1d Function analysis (one dimensional convolution)
- Compilation errors and warnings encountered in QT and their solutions
- error C4996: ‘scanf‘: This function or variable may be unsafe.Visual Studio Series compilers report errors using scanf function
- Solutions to several VTK compilation errors (vtk5.8 + VS2010)
- nginx: [warn] conflicting server name “www.yqq.org“ on 0.0.0.0:80, ignored
- Unsupported operation types unsupported operation data types
- Type definition error – one of the causes of type definition errors is WM in Oracle_ Concat function usage
- Error c2371: ‘xxx’: redefinition; different basic types solutions
- caffe deep learning [three] compilation error: fatal error: hdf5.h: No such file or directory compilation terminated.
- Pytorch RuntimeError: Error(s) in loading state_ dict for Dat aParallel:.. function submit.py Solutions for reporting errors
- C++ —Return multiple values of different types
- Typeerror: UFUNC ‘isn’t supported for the input types
- About java “Error: bad binary operator types”