Reputation: 549
Taken the following code
int main() {
int* a = (int*) malloc(sizeof(int) * 10);
free(a);
return 0;
}
If compile it to llvm IR by clang -S -emit-llvm -O0 -g
, free's declaration is:
declare i32 @free(...) #2
However, if I add #include <stdlib.h>
, free's declaration is:
declare void @free(i8*) #2
By adding include, the declaration is obviously taken from the header file, but why implicit free's declaration is different?
Upvotes: 1
Views: 62
Reputation: 61575
In C (when permitted by the operative C Standard) the implied type of a function foo
that is called without a prior
prototype or definition is int foo()
, which in C means function taking unspecified arguments, returning int.
Implicit declaration of functions is illegal as of C99 and always illegal in C++.
If you compiled exactly that code with exactly those options you will have seen
warnings for the implicit declarations of malloc
and free
, although they
do not make it clear what the implied types are. If you compiled with with clang++ instead of clang you would have seen two errors.
Upvotes: 2