In C and C++ you can get the name of the currently executing function through the __func__
macro with C99 & C++11 and ___FUNCTION___
for MSVC.
Adding to Veedrac's answer, you can get the function's name without its full path by adding this:
macro_rules! function {
() => {{
fn f() {}
fn type_name_of(_: T) -> &'static str {
std::any::type_name::()
}
let name = type_name_of(f);
// Find and cut the rest of the path
match &name[..name.len() - 3].rfind(':') {
Some(pos) => &name[pos + 1..name.len() - 3],
None => &name[..name.len() - 3],
}
}};
}
You will get my_func
instead of my::path::my_func
for example.