解释结果 [英] explain the result

查看:82
本文介绍了解释结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




帮我理解程序:

func()

{

}


main()

{

fprintf(stderr," sizeof(func):%d \ n" ;,sizeof(func));

}


输出:sizeof(func):1


我以为它会返回4个字节。因为func是一个符号,

指向函数的相对地址。但它返回1

字节。请帮我理解这个程序。


谢谢

Param

Hi

Help me to understand the program:
func()
{
}

main()
{
fprintf(stderr, "sizeof(func):%d\n", sizeof(func));
}

output: sizeof(func):1

I thought that it would return 4 bytes. since func is a symbol which
is pointing to the relative address of the function. But it returns 1
byte. Please help me to understand the program.

Thanks
Param

推荐答案

param写道:
param wrote:




帮我理解程序:

func()

{

}


main()

{

fprintf(stderr," sizeof(func):%d \ n",sizeof(func));

}


输出:sizeof(func):1


我以为它会返回4个字节。因为func是一个符号,

指向函数的相对地址。但它返回1

字节。请帮我理解这个程序。
Hi

Help me to understand the program:
func()
{
}

main()
{
fprintf(stderr, "sizeof(func):%d\n", sizeof(func));
}

output: sizeof(func):1

I thought that it would return 4 bytes. since func is a symbol which
is pointing to the relative address of the function. But it returns 1
byte. Please help me to understand the program.



好​​吧,我很惊讶你设法得到这个编译。是stderr

在您的实现上自动定义(在这种情况下它是否会损坏
),或者您是否只是在编译时没有复制确切的代码?


也就是说,你不能将sizeof应用于函数类型。如果你无论如何都要支付
,并且编译器接受它,那么无法保证将会发生什么事情。

Well, I''m surprised you managed to get this compiled at all. Is stderr
automatically defined on your implementation (in which case it''s
broken), or did you just not copy the exact code as you compiled it?

That said, you can''t apply sizeof to a function type. If you do
anyway, and the compiler accepts it, there''s no guarantee whatsoever
about what''ll happen.




" Harald van D?k" < tr ***** @ gmail.com写信息

news:11 ********************** @ l77g2000hsb。 googlegr oups.com ...

"Harald van D?k" <tr*****@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...

>我认为它会返回4个字节。因为func是一个符号,它指向函数的相对地址。但它返回1
字节。请帮我理解这个程序。
>I thought that it would return 4 bytes. since func is a symbol which
is pointing to the relative address of the function. But it returns 1
byte. Please help me to understand the program.



嗯,我很惊讶你设法得到这个编译。是stderr

在你的实现上自动定义了(在这种情况下它被打破了b $ b),还是你在编译时没有复制确切的代码?


Well, I''m surprised you managed to get this compiled at all. Is stderr
automatically defined on your implementation (in which case it''s
broken), or did you just not copy the exact code as you compiled it?



破碎是一个有点强烈的单词imo,如果编译器有标准库名称的知识,它似乎不是很糟糕,尽管我这样做明白它确实这样做。
可以编写不适用于其他抱怨编译器的代码。

broken is a bit strong word imo, it doesnt seems so bad if a compiler has
knowledge of standard library names, although i do understand that it does
make it possible to write code that wont work on other complaiant compilers.


3月25日下午3:02, " PARAM" < sparamesw ... @ gmail.comwrote:
On Mar 25, 3:02 pm, "param" <sparamesw...@gmail.comwrote:

帮我理解程序:

func()

{


}


main()

{

fprintf (stderr,sizeof(func):%d \ n,sizeof(func));


}


输出: sizeof(func):1


我以为它会返回4个字节。因为func是一个符号,

指向函数的相对地址。但它返回1

字节。请帮我理解这个程序。
Help me to understand the program:
func()
{

}

main()
{
fprintf(stderr, "sizeof(func):%d\n", sizeof(func));

}

output: sizeof(func):1

I thought that it would return 4 bytes. since func is a symbol which
is pointing to the relative address of the function. But it returns 1
byte. Please help me to understand the program.



func不是函数指针。考虑:


[tmp]

func is not a function pointer. Consider:

[tmp]


这篇关于解释结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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