In my case, I have two layers say core layer and application layer. Application layer depends of core layer.
I want that only core layer should use CRT functions.
In application layer, if any CRT function is used, it should not compile.
Is there any way to achieve this? For example, direct call to free/malloc should not be made in application layer.
One way which I thought to #define all CRT functions to some error so that Application layer cannot use direct CRT calls (Application layer is including the header files of core layer).
You don't need to #define all the funcs in CRT. It's enough to define one of the funcs declared in the header to cause compilation failure.
Also, look into the CRT headers, most of them rely on some construct of this kind:
#ifndef "some unique id"
#define "some unique id"
/* header body */
#endif
If you define this unique id, you'll effectively cause the header not to be included, thus compilation error will occur when trying to use function declared in this header.