问题描述
#define writel(value, address) \
(*(volatile unsigned int *)(address)) = (value)
我想知道上面的定义宏是类型转换还是用作函数指针.
由于使用了volatile,感到困惑
I wish to know whether a above define macro is typecasted or used as function pointer .
Got confused since volatile is used
推荐答案
(unsigned int (cdecl)())(address) = value
[edit]经过编译器检查,并修复了类型转换语法;但是编译器仍然不接受它,因为它不允许我将值分配给函数指针[/edit]
请注意在(address)
之后的另一个空集()
.它散发出一个事实,我们正在处理的是函数指针,而不是普通的指针.另外,我省略了volatile
,因为这对于返回类型是无效的限定符(换句话说,表达式中的volatile
表示这不是函数指针)
[edit]Checked with the compiler and fixed the type cast syntax; but the compiler doesn''t accept it anyway since it won''t let me assign a value to a function pointer [/edit]
Note the additional empty set of ()
after (address)
. It gives away the fact we''re dealing with a function pointer rather than an ordinary one. Also, I left out volatile
, because that''s an invalid qualifier for return types (or, in other words, the volatile
in your expression is an indication this is not a function pointer)
这篇关于类型转换还是函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!