有关于静态形参的问题。

didijiji 2012-11-28 11:53:34
我之前发过一个帖子:http://bbs.csdn.net/topics/370157740
这个帖子的大家回复说static参数本身就是一个错误的概念。


但是,我在VS2010环境下:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<windows.h>

void f(static int a)
{
printf("HelloWorld!");
}

int main()
{
int a = 13;
f(3);
printf("\n");
system("pause");
return 0;
}


输出结果:
HelloWorld!


麻烦高手出来解答一下,static参数到底是未定义的行为还是有什么特殊的意义?
...全文
285 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
didijiji 2012-12-04
  • 打赏
  • 举报
回复
引用 15 楼 mymtom 的回复:
C99 6.7.5.3 Function declarators (including prototypes) Constraints 1 A function declarator shall not specify a return type that is a function type or an array type. 2 The only stora……
谢谢,明白了。
mymtom 2012-12-04
  • 打赏
  • 举报
回复
C99 6.7.5.3 Function declarators (including prototypes) Constraints 1 A function declarator shall not specify a return type that is a function type or an array type. 2 The only storage-class specifier that shall occur in a parameter declaration is register. 3 An identifier list in a function declarator that is not part of a definition of that function shall be empty. 4 After adjustment, the parameters in a parameter type list in a function declarator that is part of a definition of that function shall not have incomplete type. Semantics
mymtom 2012-12-04
  • 打赏
  • 举报
回复
无数的事实证明GCC是最标准的编译器. C89 3.5.4.3 Function declarators (including prototypes) Constraints A function declarator shall not specify a return type that is a function type or an array type. The only storage-class specifier that shall occur in a parameter declaration is register. An identifier list in a function declarator that is not part of a function definition shall be empty.
ForestDB 2012-12-04
  • 打赏
  • 举报
回复
第一VS不是唯一,第二VS也不见得就是标准的代表。
pengzhixi 2012-12-04
  • 打赏
  • 举报
回复
Each parameter has automatic storage duration 这个是标准规定的。automatic storage就意味着参数不可能有static 这个storage-class修饰
newtee 2012-12-04
  • 打赏
  • 举报
回复
没见过这样写的函数 不要迷信编译器 初学C语言建议不要拿VS做编译器 用TC比较好 VS把很多地方都优化了 不适合新手 况且VS也不是主要拿来编译C语言
didijiji 2012-12-04
  • 打赏
  • 举报
回复
引用 9 楼 zhuankeshumo 的回复:
引用 6 楼 didijiji 的回复:引用 4 楼 zhuankeshumo 的回复:楼主不要误导小孩啊 这位仁兄有何高见,请讲? 函数有这样的吗?void f(static int a){}
但是在VS 2010环境下的确可以通过编译,并运行出结果啊。
newtee 2012-12-04
  • 打赏
  • 举报
回复
引用 6 楼 didijiji 的回复:
引用 4 楼 zhuankeshumo 的回复:楼主不要误导小孩啊 这位仁兄有何高见,请讲?
函数有这样的吗?void f(static int a){}
didijiji 2012-12-04
  • 打赏
  • 举报
回复
引用 2 楼 anhuizhuanjiao 的回复:
形参设为静态局部变量可是可以,可惜没什么作用啊,因为每次调用函数都会给形参赋值
你的意思是说加了跟没加一个样是吧?
didijiji 2012-12-04
  • 打赏
  • 举报
回复
引用 3 楼 ForestDB 的回复:
gcc: error: storage class specified for parameter ‘a’
但是我的VS是可以的啊,就是说static参数是非标准定义的,也就是说是未定义行为是吧?
didijiji 2012-12-04
  • 打赏
  • 举报
回复
引用 4 楼 zhuankeshumo 的回复:
楼主不要误导小孩啊
这位仁兄有何高见,请讲?
BYD123 2012-11-29
  • 打赏
  • 举报
回复
Make no sense!
转角天边 2012-11-28
  • 打赏
  • 举报
回复
形参设为静态局部变量可是可以,可惜没什么作用啊,因为每次调用函数都会给形参赋值
dhdahai 2012-11-28
  • 打赏
  • 举报
回复
长见识了
newtee 2012-11-28
  • 打赏
  • 举报
回复
楼主不要误导小孩啊
ForestDB 2012-11-28
  • 打赏
  • 举报
回复
gcc: error: storage class specified for parameter ‘a’

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧