I'm having the following warning, when trying to compile standard
library functions, like strlen, memset, etc.
warning: incompatible redeclaration of library function 'strlen'
size_t strlen(const char *s);
note: 'strlen' is a builtin with type 'unsigned int (char const *)'
size_t is a typedef for unsigned long. clang CFLAGS include -std=c99
I'm not sure how to solve this. It would be useful if size_t were
defined as unsigned long. Any advice ?
clang internally defines size_t according to the selected target;
what's your CPU/OS? Or are you trying to do something unusual?
(-fno-builtin will get rid of this warning, but it's kind of overkill
in this case).
This is almost good to me, however there are some parts of the
library (ie, in printf) that require the use of the equivalent signed
version of size_t (for example, to print the argument "%zd"). Is there
a way to get this in clang ? Else, I'll have to define size_t in per
case basis. Same for ptrdiff_t.
Ah... that's kind of messy. If you make the assumption that size_t
and ptrdiff_t are either short, int, long, or long long, you can
probably pull it off with a combination of typeof,
__builtin_choose_expr, and __builtin_types_compatible_p.
Also, what's the expected behavior of redefining a built-in function ?
Redeclaring a built-in function with a compatible prototype is okay.
If you need to define library functions, you should pass in
-fno-builtin on the command-line.