Is there any macro which will remove double quotes and ‘\0’ in a string?
For example:-
“HELLO\0” -> HELLO
Edited:-
Actually I want to get the function address. So I thought to use FUNC Macro to get the function name and stipping out double quotes and ‘\0’ will help me to get the function address.
for ex:
#define FUN_PTR fun
#define FUN_NAME "fun"
void fun(){
printf("fun add %p name %s\n",FUN_PTR,FUN_NAME);
}
To avoid user define macros. I like to know other methods to derive these functionality :).
void fun(){
printf("fun add %p name %s\n",<SOME_MACRO>(__FUNC__),__FUNC__);
}
Do it the other way around.
Inside a macro, if
xis a macro argument, then#xis the string version.Typically, if you use this a lot, then you’ll want to define a helper function to work around the weak type system in C:
Note that this won’t work for getting the address of the current function.
__FUNC__is not a macro and it is not a string literal, it has no double quotes. You cannot use__FUNC__to get the address of the function without some serious trickery, and it will break half the time. For example:However, this will not work half the time —
dlsymwasn’t designed to be used for that purpose.