奇怪的功能使用 [英] Strange function use
问题描述
在基准测试中我发现了一个不常用的函数。
这是简化形式:
1 int foo(int f)
2 {
3返回f;
4}
5
6 int main(无效)
7 {
8 int a,b,foo();
9 a = 10;
10 b = foo(a);
11
12返回0;
13}
我不明白函数foo的使用第8行。
它的目的是什么?它被称为没有为任何变量分配它的'/ b
返回值。此外,我想知道
为什么允许使用此功能。根据
函数原型foo期望第8行中没有给出整数参数
。使用
" gcc -Wall -ansi"编译代码没有发出任何警告/错误。
你能否解释一下。
问候,
Chris
Hi,
in a benchmark I''ve found an uncommon use of a function.
This is the simplified form:
1 int foo( int f )
2 {
3 return f;
4 }
5
6 int main( void )
7 {
8 int a, b, foo();
9 a = 10;
10 b = foo( a );
11
12 return 0;
13 }
I don''t understand the use of function "foo" in line 8.
What''s it''s purpose? It''s called without assigning it''s
return value to any variable. Furthermore, I wonder
why this function use is allowed at all. According to
the function prototype "foo" expects an integer argument
that is in line 8 not given. Compiling the code with
"gcc -Wall -ansi" does not issue any warning/errors.
Could you shed some light on that.
Regards,
Chris
推荐答案
Christian Christmann写道:
Christian Christmann wrote:
这是简化形式:
1 int foo (int f)
2 {
3返回f;
4}
5
6 int main(无效)
7 {
8 int a,b,foo();
9 a = 10;
10 b = foo(a);
11
12返回0;
13}
我不理解函数foo的使用第8行。
它的目的是什么?它被称为没有为任何变量分配它的'/ b
返回值。此外,我想知道
为什么允许使用此功能。根据
函数原型foo期望第8行中没有给出整数参数
。使用
" gcc -Wall -ansi"编译代码没有发出任何警告/错误。
你能否解释一下。
Hi,
in a benchmark I''ve found an uncommon use of a function.
This is the simplified form:
1 int foo( int f )
2 {
3 return f;
4 }
5
6 int main( void )
7 {
8 int a, b, foo();
9 a = 10;
10 b = foo( a );
11
12 return 0;
13 }
I don''t understand the use of function "foo" in line 8.
What''s it''s purpose? It''s called without assigning it''s
return value to any variable. Furthermore, I wonder
why this function use is allowed at all. According to
the function prototype "foo" expects an integer argument
that is in line 8 not given. Compiling the code with
"gcc -Wall -ansi" does not issue any warning/errors.
Could you shed some light on that.
这不是/ call /而是声明 - 它说foo是一个函数
返回一个int 。我相信这也是/说/ foo需要一个未知的
数/类型的args - 但是,由于foo的定义在范围内,编译器
已经知道了...因此第8行的声明是没有必要的。
-
======== ======
不是学生
==============
It''s not a /call/ but a declaration - it''s say that foo is a function
returning an int. I believe it''s also /saying/ that foo takes an unknown
number/type of args - however, as foo''s definition is in scope, the compiler
already knows about it ... thus the declaration in line 8 isn''t necessary.
--
==============
Not a pedant
==============
>
Christian Christmann写道:
Christian Christmann wrote:
1 int foo(int f)
2 {
3返回f;
4}
5
6 int main(无效)
7 {
8 int a,b,foo();
1 int foo( int f )
2 {
3 return f;
4 }
5
6 int main( void )
7 {
8 int a, b, foo();
int a,b,foo(int);
int a, b, foo( int );
9 a = 10;
10 b = foo(a);
11
12返回0;
13}
我不明白函数foo的使用第8行。
它的目的是什么?它被称为没有为任何变量分配它的'/ b
返回值。此外,我想知道
返回任何变量的值。此外,我想知道
为什么允许使用此功能。根据
函数原型foo期望第8行中没有给出整数参数
。使用
" gcc -Wall -ansi"编译代码不会发出任何警告/错误。
9 a = 10;
10 b = foo( a );
11
12 return 0;
13 }
I don''t understand the use of function "foo" in line 8.
What''s it''s purpose? It''s called without assigning it''s
return value to any variable. Furthermore, I wonder
return value to any variable. Furthermore, I wonder
why this function use is allowed at all. According to
the function prototype "foo" expects an integer argument
that is in line 8 not given. Compiling the code with
"gcc -Wall -ansi" does not issue any warning/errors.
int foo(); / * int foo(int); * /
它不是函数use / call,foo()发生在声明中。它是
函数原型声明。
int foo( ); /*int foo( int );*/
It''s not a function use/call, foo() occurs inside a declaration. It''s a
function prototype declaration.
Christian Christmann写道:
Christian Christmann wrote:
1 int foo(int f)
2 {
3返回f;
4}
5
6 int main(无效)
7 {
8 int a,b,foo();
1 int foo( int f )
2 {
3 return f;
4 }
5
6 int main( void )
7 {
8 int a, b, foo();
int a,b,foo(); / * A * /
int a,b = foo(); / * B * /
int a, b, foo(); /*A*/
int a, b = foo(); /*B*/
9 a = 10;
10 b = foo(a);
11
12返回0;
13}
9 a = 10;
10 b = foo( a );
11
12 return 0;
13 }
区分A行和B行。函数调用发生在第B行。
Differentiate line A and B. A function call occurs at line B.
这篇关于奇怪的功能使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!