FAQ 1.12 - auto关键字 [英] FAQ 1.12--auto keyword

查看:81
本文介绍了FAQ 1.12 - auto关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

faq(问题1.12)指出关键字auto完全是

没用。

但是,有必要转发声明一个嵌套函数(对于

gcc ...我不是确定这是gcc特定还是语言问题。)

换句话说:


int

main(void)

{

AUTO int foo(void);

返回0;


int foo(void )

{

返回0;

}

}


仅在AUTO为auto时才有效。而不是空的。这是一种语言

问题,还是允许前向声明为gcc扩展?

如果语言问题,是否应该修改常见问题解答?

The faq (question 1.12) states that the keyword "auto" is completely
useless.
However, it is necessary to forward declare a nested function (for
gcc...I''m not sure if this is gcc specific or a language issue.)
In other words:

int
main(void)
{
AUTO int foo(void);
return 0;

int foo (void)
{
return 0;
}
}

is valid only if AUTO is "auto" and not empty. Is this a language
issue, or is allowing the forward declaration a gcc extension?
If a language issue, should the FAQ be modified?

推荐答案

Bill Pursell写道:
Bill Pursell wrote:
faq(问题1.12)声明关键字auto完全没用。
但是,有必要转发声明一个嵌套函数(对于
gcc ......我不确定这是gcc特定还是语言问题。)


具体是gcc。嵌套函数不是正确语言的一部分。

标准C不允许函数声明嵌套。

换句话说:

int
main(无效)
{
AUTO int foo(void);
返回0;

int foo(void)
{}
}

才有效而不是空的。这是一个语言
问题,还是允许前向声明gcc扩展?


嵌套函数作为一个整体是gcc扩展,更不用说向前声明

了。

如果语言问题,应该常见问题解答被修改?
The faq (question 1.12) states that the keyword "auto" is completely
useless.
However, it is necessary to forward declare a nested function (for
gcc...I''m not sure if this is gcc specific or a language issue.)
It''s gcc specific. Nested functions are not part of the language proper.
Standard C does not allow function declarations to nest.
In other words:

int
main(void)
{
AUTO int foo(void);
return 0;

int foo (void)
{
return 0;
}
}

is valid only if AUTO is "auto" and not empty. Is this a language
issue, or is allowing the forward declaration a gcc extension?
Nested functions as a whole are a gcc extension, let alone forward declaring
them.
If a language issue, should the FAQ be modified?



它不是,并且常见问题解答中的注释不是明智的,IMO,因为它太具体了。


S.


It''s not, and a note in the FAQ would not be wise, IMO, as this gets too
specific.

S.


" Bill Pursell" <双********** @ gmail.com>写道:
"Bill Pursell" <bi**********@gmail.com> writes:
faq(问题1.12)指出关键字auto完全没用。
但是,有必要转发声明一个嵌套函数(对于
gcc ......我不确定这是gcc特定还是语言问题。)
换句话说:

int
main(无效)
{
AUTO int foo(void);
返回0;

int foo(无效)
{
返回0;
}


仅在AUTO为auto时有效;而不是空的。这是一个语言
问题,还是允许前向声明gcc扩展名?
如果语言问题,是否应修改FAQ?
The faq (question 1.12) states that the keyword "auto" is completely
useless.
However, it is necessary to forward declare a nested function (for
gcc...I''m not sure if this is gcc specific or a language issue.)
In other words:

int
main(void)
{
AUTO int foo(void);
return 0;

int foo (void)
{
return 0;
}
}

is valid only if AUTO is "auto" and not empty. Is this a language
issue, or is allowing the forward declaration a gcc extension?
If a language issue, should the FAQ be modified?




标准C不允许嵌套函数定义。


gcc本可以告诉你这个:


%gcc -c -ansi - pedantic -DAUTO = auto tmp.c

tmp.c:函数`main'':

tmp.c:4:警告:函数`foo的存储类无效''

tmp.c:8:警告:ISO C禁止嵌套函数

tmp.c:10:警告:ISO C90禁止混合声明和代码


(与-std = c99相同,除了最后一个警告不会出现
。)


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http ://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



Standard C doesn''t allow nested function definitions.

gcc could have told you this:

% gcc -c -ansi -pedantic -DAUTO=auto tmp.c
tmp.c: In function `main'':
tmp.c:4: warning: invalid storage class for function `foo''
tmp.c:8: warning: ISO C forbids nested functions
tmp.c:10: warning: ISO C90 forbids mixed declarations and code

(Same thing with "-std=c99", except that the last warning doesn''t
show up.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Skarmander写道:
Skarmander wrote:
Bill Pursell写道:
Bill Pursell wrote:
the faq(问题1.12 )声明关键字auto完全没用。
但是,有必要转发声明一个嵌套函数(对于
gcc ......我不确定这是gcc特定还是语言问题。)
The faq (question 1.12) states that the keyword "auto" is completely
useless.
However, it is necessary to forward declare a nested function (for
gcc...I''m not sure if this is gcc specific or a language issue.)



这是特定的gcc。嵌套函数不是正确语言的一部分。
标准C不允许函数声明嵌套。



It''s gcc specific. Nested functions are not part of the language proper.
Standard C does not allow function declarations to nest.



那应该是定义。在

函数中允许使用函数声明,但通常不会这样做。


S.


That should be "definitions". A function declaration is allowed within a
function, although this is generally not done.

S.


这篇关于FAQ 1.12 - auto关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆