Why can't I specify the storage class for formal parameters of a function?

萝らか妹 提交于 2019-12-03 14:02:57

First,quoting C11, chapter 6.7.6.3

The only storage-class specifier that shall occur in a parameter declaration is register.

So, this is explicitly specified in the standard.

That said, this restriction exists because with an explicit storage class like static/ extern, there will be problems in memory management, as function parameters are in the block scope for the function and their lifetimes are limited to the execution of the function body.

  • A parameter variable cannot outlive the call to the function; otherwise, what would be the effect of the argument in the next call to the same function? So static storage is not meaningful, and auto is redundant.

  • Since the function parameters has no linkage, extern also makes no sense.


Additionally, as mentioned in C11, for a hosted environment, the conforming signature for main() is int main(void), at least.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!