在git的源代码中,我看到了以下函数定义
const char *typename(unsigned int type)
{
if (type >= ARRAY_SIZE(object_type_strings))
return NULL;
return object_type_strings[type];
}
我相信这typename
是一个函数,但似乎是一个const
函数,这对我来说很混乱。
这是什么意思?如何使用此const
功能?
链接到源鳕鱼;https://github.com/git/git/blob/7d722536dd86b5fbd0c0434bfcea5588132ee6ad/object.c#L29
使用 cdecl
% cdecl
cdecl> explain const char *typename(unsigned int)
declare typename as function (unsigned int) returning pointer to const char
有时它是一个有用的工具,但受到很大限制,例如它说
cdecl> explain const char *typename(unsigned int foo);
syntax error
但是,在尝试理解函数指针时,它非常有用:
cdecl> declare a as pointer to function (int, double, pointer to const char)
returning pointer to const volatile struct foo
const volatile struct foo *(*a)(int , double , const char *)
或者
cdecl> explain const void *(*b[])(int , char (*(*)(char ))(double))
declare b as array of pointer to function (int, pointer to function (char) returning pointer
to function (double) returning char) returning pointer to const void
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句