Why does the compiler warn about and ignore the call to my function strlen? [closed]-Collection of common programming errors

It is perfectly legal to ignore the return value of a function. You probably do it more than 99% of the times you invoke printf() (which returns an int).

However, as several persons have said in the comments, you called your function strlen() after a standard library function. This is illegal according to C99’s 7.1.3:2:

If the program declares or defines an identifier in a context in which it is reserved (other than as allowed by 7.1.4), or defines a reserved identifier as a macro name, the behavior is undefined.

Here the compiler warns unexpectedly, and either calls the standard function instead of yours, or calls no function at all (since it knows its strlen() is supposed to be without side-effects). This is one of the things undefined behavior can do.

Originally posted 2013-11-09 21:27:07.