__FUNCTION__
时间: 2023-10-20 13:07:34 浏览: 36
__FUNCTION__ is a predefined PHP constant that returns the name of the current function in which it is used. It is useful for debugging purposes and for logging function calls. It can be used inside a function to display its name, or in a debugging statement to display the name of the function where the statement is located. For example:
```
function myFunction() {
echo "This is " . __FUNCTION__ . "().";
}
myFunction(); // Output: This is myFunction().
```
相关问题
__function__
__FUNCTION__和__func__都是C语言中的预定义标识符,用于获取当前函数的名称。
在引用中,__FUNCTION__是一个宏,可以在函数内部使用,它会返回当前函数的名称。通过将__FUNCTION__作为参数传递给show_name函数,可以将当前函数的名称打印出来。
在引用中,__func__是C99标准引入的一个常量字符数组,它也可以用于获取当前函数的名称。与__FUNCTION__不同的是,__func__不是一个宏,而是一个隐式声明的常量字符数组。
以下是两个例子来演示__FUNCTION__和__func__的使用:
1. 使用__FUNCTION__宏获取当前函数的名称:
```c
#include <iostream>
void show_name(const char* name) {
std::cout << name << std::endl;
}
void myfunc() {
show_name(__FUNCTION__); // 输出:myfunc
}
void foo() {
show_name(__FUNCTION__); // 输出:foo
}
```
2. 使用__func__常量字符数组获取当前函数的名称:
```c
#include <iostream>
void show_name(const char* name) {
std::cout << name << std::endl;
}
void myfunc() {
show_name(__func__); // 输出:myfunc
}
void foo() {
show_name(__func__); // 输出:foo
}
```
类似__FUNCTION__
类似于__FUNCTION__的宏有__func__和__PRETTY_FUNCTION__。其中,__func__是用来获取当前函数的名字的,而__PRETTY_FUNCTION__是用来返回函数的详细信息的,包括函数所属的类等信息。
举例说明如下:
```cpp
#include <iostream>
void TestFunction(){
std::cout << "Output of __FUNCTION__ is: " << __FUNCTION__ << std::endl;
}
int main(){
std::cout << "Output of __FUNCTION__ is: " << __FUNCTION__ << std::endl;
TestFunction();
return 0;
}
```
在上述的例子中,__FUNCTION__会分别输出main和TestFunction。
另外,GCC实现了__PRETTY_FUNCTION__这个函数宏,它可以以::()的格式输出成员函数的详细信息,包括类名和函数的参数类型。在C程序中,__PRETTY_FUNCTION__和__FUNCTION__的功能是相同的。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [__PRETTY_FUNCTION__, __FUNCTION__, __func__ 在C/C++中的差异?](https://blog.csdn.net/weixin_40463424/article/details/124566427)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]