Can a C program take the address of a function defined in the standard library, and if so, under what conditions?
No, not in general.
According to [namespace.std], forming a pointer to a standard library function is unspecified behavior unless the function is designated as addressable. This applies to member functions as well.
std::invoke(std::boolalpha, std::cout);
In this example, std::boolalpha is an addressable function designated by [fmtflags.manip]. Therefore, this line is well-formed and equivalent to:
std::cout.setf(std::ios_base::boolalpha);
std::invoke(static_cast<ctype_func>(std::tolower), 'A');
However, for functions defined in
The unexpected output is not guaranteed, and the code may not even compile. This also applies to member functions declared in the C standard library.
The above is the detailed content of Can I Get the Address of a Standard Library Function in C ?. For more information, please follow other related articles on the PHP Chinese website!