Project headers

In the previous section, we saw how to restrict ourselves to various standardized and hopefully portable subsets of the functions available to us. However, we may want to be even more restrictive.

For example, for the sake of safety, we may wish to prohibit functions that are vulnerable to buffer overruns, such as strcpy(), sprintf(), gets(), and sscanf(). Similarly, in the case of a multi-threaded program, we may wish to prohibit functions that are known to be non-reentrant, such as asctime(), ctime() etc.

So, we do not #include standard headers directly. What we do is define a project header for each standard header, that includes the standard header and then excludes the relevant functions. Thus we would define proj_string.h corresponding to string.h as follows:

	#ifndef H_proj_string
	#define H_proj_string

	#define strcpy_is_prohibited()
	#define strcpy(_x,_y)	strcpy_is_prohibited_in_this_project(_x,_y)

	#define strcat_is_prohibited()
	#define strcat(_x,_y)	strcat_is_prohibited_in_this_project(_x,_y)

	#define strtok_is_prohibited()
	#define strtok(_x,_y)	strtok_is_prohibited_in_this_project(_x,_y)


I have not come up with a truly satisfactory method for making a function illegal. In the case of the construct used above:

Next Prev Main Top Feedback