GCC or make flag disable certain standard library functions

I am working on a multi-threaded project that has suffered from many errors due to the use of the strtok () library function, which is not thread safe.

I would like to find a way to prohibit the use of this function (and possibly others) by defining something in the project file (Qt Creator / qmake) (for example, overriding a symbol) so that new developers or experienced developers introduce it again.

Any ideas?

+5
source share
1 answer

this is what the GCC manual says about eliminating the use of certain library functions:

#pragma GCC poison Sometimes, there is an identifier that you want to remove completely from your program, and make sure that it never creeps back in. To enforce this, you can poison the identifier with this pragma. #pragma GCC poison is followed by a list of identifiers to poison. If any of those identifiers appears anywhere in the source after the directive, it is a hard error. For example, #pragma GCC poison printf sprintf fprintf sprintf(some_string, "hello"); will produce an error. If a poisoned identifier appears as part of the expansion of a macro which was defined before the identifier was poisoned, it will not cause an error. This lets you poison an identifier without worrying about system headers defining macros that use it. For example, #define strrchr rindex #pragma GCC poison rindex strrchr(some_string, 'h'); will not produce an error. 
+1
source

Source: https://habr.com/ru/post/1236729/


All Articles