誰かが特定の関数 (memcpy など) をコードで使用している場合、エラーが返されるようにするにはどうすればよいですか。
一部の内部設計機能を使用して、コードから memcpy のすべてのインスタンスを削除しました。
私が確認したいのは、誰かが将来memcpyを使用するたびに、コンパイラがエラーメッセージをスローすることです.
誰かが特定の関数 (memcpy など) をコードで使用している場合、エラーが返されるようにするにはどうすればよいですか。
一部の内部設計機能を使用して、コードから memcpy のすべてのインスタンスを削除しました。
私が確認したいのは、誰かが将来memcpyを使用するたびに、コンパイラがエラーメッセージをスローすることです.
You can use the preprocessor for this, like
#define memcpy(a, b, c) do_not_use_memcpy
Put that in a header file that is included in all source files, and the preprocessor will replace all calls to memcpy
with the (undefined) symbol do_not_use_memcpy
. As that symbol is undefined, you will get a compiler error about it.
ライブラリが壊れないようにするには、次のdeprecated
属性を使用します。
void * my_new_memcpy ( void * destination, const void * source, size_t num )
{
return memcpy(destination, source, num);
} __attribute__((deprecated));
// Make sure this is used *after* declaring the function
#define memcpy my_new_memcpy