我怎么知道它是一个宏还是实际上是一个函数? [英] How can I know it is a macro or actually is a function?

查看:58
本文介绍了我怎么知道它是一个宏还是实际上是一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


当我试图为我的OS课程反汇编一个简单的C程序时,我发现
函数调用函数longjmp是实际上在linux下调用了siglongjmp




同样,在windows XP下,调用setjmp和longjmp调用

分别是_setjmp3和_longjmp。有人告诉我他们是宏。


然后我想问一下,我怎么知道我正在看的东西是宏还是

不行?如果是的话,如何找出正在工作的真正的家伙?


Thanka很多。


Shi

Hi there,

While I was trying to disassemble a simple C program for my OS course, I
found that the call to function longjmp is actually called to siglongjmp
under linux.

And similarly, under windows XP, call to setjmp and longjmp are called to
_setjmp3 and _longjmp respectively. Somebody told me they are macros.

Then I want to ask, how can I know the thing I am looking at is a macro or
not? If it is, how to find out the real guy that is doing the job?

Thanka a lot.

Shi

推荐答案

On Sun,07 Sep 2003 23:06:01 -0400,Shi Jin < ji ******** @ hotmail.com>

在comp.lang.c中写道:
On Sun, 07 Sep 2003 23:06:01 -0400, "Shi Jin" <ji********@hotmail.com>
wrote in comp.lang.c:
你好,
当我试图为我的OS课程反汇编一个简单的C程序时,我发现函数longjmp的调用实际上是在linux下调用了siglongjmp

同样,在Windows XP下,调用setjmp和longjmp分别调用
_setjmp3和_longjmp。有人告诉我他们是宏。

然后我想问一下,我怎么知道我看的东西是宏还是
不是?如果是的话,如何找出正在做这个工作的真人?

Thanka很多。

Hi there,

While I was trying to disassemble a simple C program for my OS course, I
found that the call to function longjmp is actually called to siglongjmp
under linux.

And similarly, under windows XP, call to setjmp and longjmp are called to
_setjmp3 and _longjmp respectively. Somebody told me they are macros.

Then I want to ask, how can I know the thing I am looking at is a macro or
not? If it is, how to find out the real guy that is doing the job?

Thanka a lot.

Shi




您可以做的第一件事是购买并阅读

标准的副本。 setjmp必须是一个宏。


一般来说,实际上没有办法告诉库函数,

,因为C标准允许实现提供任何和所有标准库函数的

宏版本。


另一方面,还需要实现提供

所有标准库函数的实际函数版本是

必须是函数(不是setjmp,具体不是

函数)。您可以强制实现调用函数

版本,而不是通过在函数的

名称周围加括号来扩展宏:


size_t the_size = strlen(a_char_pointer); / *可以使用宏* /

size_t the_size =(strlen)(a_char_pointer); / *不能是宏* /


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo .com /~scs / C-faq / top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c -c ++ ftp://snurse-l.org/pub/acllc- c ++ / faq



The first thing that you can do is buy and read a copy of the
standard. setjmp is required to be a macro.

There is really no way to tell about library functions in general,
however, because the C standard allows an implementation to provide a
macro version of any and all standard library functions.

On the other hand, an implementation is also required to provide
actual function versions of all standard library functions that are
required to be functions (not setjmp, which is specifically not a
function). You can force the implementation to call the function
version rather than expand the macro by putting parentheses around the
name of the function:

size_t the_size = strlen(a_char_pointer); /* could use a macro */

size_t the_size = (strlen)(a_char_pointer); /* can''t be macro */

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq


Jack Klein写道:
Jack Klein wrote:
On Sun,07 Sep 2003 23:06:01 -0400," 史进 < ji ******** @ hotmail.com>
在comp.lang.c中写道:

On Sun, 07 Sep 2003 23:06:01 -0400, "Shi Jin" <ji********@hotmail.com>
wrote in comp.lang.c:

你好,
当我试图为我的OS课程反汇编一个简单的C程序时,我发现函数longjmp的调用实际上是在linux下调用了siglongjmp

同样,在Windows XP下,调用setjmp和longjmp分别调用
_setjmp3和_longjmp。有人告诉我他们是宏。

然后我想问一下,我怎么知道我看的东西是宏还是
不是?如果是的话,如何找出正在做这项工作的真人?

Thanka很多。

Hi there,

While I was trying to disassemble a simple C program for my OS course, I
found that the call to function longjmp is actually called to siglongjmp
under linux.

And similarly, under windows XP, call to setjmp and longjmp are called to
_setjmp3 and _longjmp respectively. Somebody told me they are macros.

Then I want to ask, how can I know the thing I am looking at is a macro or
not? If it is, how to find out the real guy that is doing the job?

Thanka a lot.

Shi



您可以做的第一件事是购买并阅读
标准的副本。 setjmp必须是一个宏。

一般来说,没有办法告诉库函数,但是,因为C标准允许一个实现提供一个
宏任何和所有标准库函数的版本。


The first thing that you can do is buy and read a copy of the
standard. setjmp is required to be a macro.

There is really no way to tell about library functions in general,
however, because the C standard allows an implementation to provide a
macro version of any and all standard library functions.




如果你真的想知道某些东西是不是宏,你可以尝试

使用编译器的预处理器来扩展所有宏。

你需要能够只调用你的预处理器。阅读你的

编译器文档,了解如何执行此操作。

准备在结果中进行一些搜索,因为预处理

代码通常有点更难读。这可能就是为什么宏发明的原因了。


Mark



If you really want to know if something is a macro or not, you could try
to use the preprocessor of your compiler to get all the macros expanded.
You need to be able to call your preprocessor only ofcourse. Read your
compiler documentation on how to do this.
Be prepared to do some searching in the result, because preprocessed
code is usually somewhat harder to read. That''s probably why macros were
invented.

Mark


>然后我想问一下,我怎么知道我正在看的东西是宏还是
> Then I want to ask, how can I know the thing I am looking at is a macro or
不是?如果是的话,如何找出正在做这项工作的真人?
not? If it is, how to find out the real guy that is doing the job?



< OT>


只是这一部分你的问题(无论杰克说什么,或者说是否持有b $ b)可能有两种方式


1.因为你使用的是linux(这是最好的)可能意味着您正在使用

gcc),您可以将代码编译为gcc -E以查看后处理器输出。


2.您可以查看使用nm或objdump的符号表。如果你比较

使用宏时的转储,当你不使用时,你可以注意到某些函数出现在转储中很可能是什么

宏扩展到......


< / OT>


<OT>

For just this part of your question (irrespective of what Jack said
held or not) there could be two ways

1. Since you''re using linux (which would most likely mean you''re using
gcc) , you could compile code as gcc -E to see the post processor output.

2. You could check the symbol table using nm or objdump. If you compare
the dumps when you use the macro and when you don''t , you can notice
some functions showing up in the dump which are most likely what the
macro expands to...

</OT>


这篇关于我怎么知道它是一个宏还是实际上是一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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