Call a function instead of a macro in C

My question is: if you have a macro and a function with the same name, only the macro will be called, right? What if I want to call a function instead of a macro?

+5
source share
3 answers

If you have a function and a functional macro named fooand you want to call the version of the function, you can do:

(foo)(args)

This works because for function names like macros, a list of arguments in parentheses should be followed for substitution.

This is specified in clause 7.1.4 / 1 of ISO C99:

, , , , , ​​, , , , . , , . , . #undef , .

, , , , , . , .

+12

. , , , .

+1

Provide a trick before the challenge

#ifdef foo
#undef foo
#endif //

Therefore, locally in a single file that calls the function, you will always have explicit behavior

+1
source

All Articles