首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

有关于静态形参的有关问题

2013-01-04 
有关于静态形参的问题。我之前发过一个帖子:http://bbs.csdn.net/topics/370157740这个帖子的大家回复说sta

有关于静态形参的问题。
我之前发过一个帖子: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参数到底是未定义的行为还是有什么特殊的意义?
[解决办法]
形参设为静态局部变量可是可以,可惜没什么作用啊,因为每次调用函数都会给形参赋值
[解决办法]
gcc:
error: storage class specified for parameter ‘a’

[解决办法]
Make no sense!
[解决办法]
没见过这样写的函数  不要迷信编译器  初学C语言建议不要拿VS做编译器  用TC比较好  VS把很多地方都优化了  不适合新手
况且VS也不是主要拿来编译C语言
[解决办法]
Each parameter has automatic storage duration

这个是标准规定的。automatic storage就意味着参数不可能有static 这个storage-class修饰
[解决办法]
第一VS不是唯一,第二VS也不见得就是标准的代表。

[解决办法]
无数的事实证明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.

热点排行