3

誰かが特定の関数 (memcpy など) をコードで使用している場合、エラーが返されるようにするにはどうすればよいですか。

一部の内部設計機能を使用して、コードから memcpy のすべてのインスタンスを削除しました。

私が確認したいのは、誰かが将来memcpyを使用するたびに、コンパイラがエラーメッセージをスローすることです.

4

2 に答える 2

5

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.

于 2013-07-11T11:06:41.060 に答える
4

ライブラリが壊れないようにするには、次の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
于 2013-07-11T11:06:46.580 に答える