C是否对函数的参数名称具有__func__功能? [英] Does C have __func__ functionality for names of the arguments of a function?

查看:93
本文介绍了C是否对函数的参数名称具有__func__功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数参数名称的"C"标准是否支持类似于__func__的内容?

Does the "C" standard support something similar to __func__ for the function arguments' names?

推荐答案

如果您想要一种快速而又肮脏的解决方案,请制作如下的预处理器宏...

if you want a quick and dirty solution for this make pre-processor macros like this...

#define FUNCTION_HEADER(a) a { const char* __func__ = #a;
#define FUNCTION_FOOTER() }

...,并将其用于函数的页眉和页脚(已通过VS 2008测试):

... and use it for your function headers and footers like this (tested with VS 2008):

#include <windows.h>

#define FUNCTION_HEADER(a) a { const char* __func__ = #a;
#define FUNCTION_FOOTER() }

FUNCTION_HEADER( int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) )
    MessageBoxA(0, __func__, __func__, MB_OK);
    return 0;
FUNCTION_FOOTER()

这应该可以按照您想要的方式工作,但是很难看.

This should work exactly how you want, but it is ugly.

这篇关于C是否对函数的参数名称具有__func__功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆