...
Non-Compliant Code Example: (function pointers)
In this example, the function pointer fp
is used to refer to the function strchr()
, which is defined elsewhere. However, fp
is defined without the appropriate parameter list, and the function prototype for strchr()
is not visible to this program. As a result there is no type checking performed on the call to fp(12,2);
.
Code Block | ||
---|---|---|
| ||
#include <stdio.h> extern char *strchr(); char *(*fp) (); int main(void) { char *c; fp = strchr; c = fp(12,2); printf("%s\n",c); } |
Wiki Markup |
---|
Note that this example also violates recommendation \[[DCL07-A. Include the appropriate type information in function declarators]\]. |
Compliant Solution: (function pointers)
...