本文介绍了我怎么知道它是一个宏还是实际上是一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好, 当我试图为我的OS课程反汇编一个简单的C程序时,我发现函数调用函数longjmp是实际上在linux下调用了siglongjmp 。 同样,在windows XP下,调用setjmp和longjmp调用 分别是_setjmp3和_longjmp。有人告诉我他们是宏。 然后我想问一下,我怎么知道我正在看的东西是宏还是 不行?如果是的话,如何找出正在工作的真正的家伙? Thanka很多。 ShiHi there,While I was trying to disassemble a simple C program for my OS course, Ifound that the call to function longjmp is actually called to siglongjmpunder 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 ornot? 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 ++ / faqThe first thing that you can do is buy and read a copy of thestandard. 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 amacro version of any and all standard library functions.On the other hand, an implementation is also required to provideactual function versions of all standard library functions that arerequired to be functions (not setjmp, which is specifically not afunction). You can force the implementation to call the functionversion rather than expand the macro by putting parentheses around thename 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 KleinHome: http://JK-Technology.ComFAQs forcomp.lang.c http://www.eskimo.com/~scs/C-faq/top.htmlcomp.lang.c++ http://www.parashift.com/c++-faq-lite/alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq 您可以做的第一件事是购买并阅读标准的副本。 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. 如果你真的想知道某些东西是不是宏,你可以尝试 使用编译器的预处理器来扩展所有宏。 你需要能够只调用你的预处理器。阅读你的 编译器文档,了解如何执行此操作。 准备在结果中进行一些搜索,因为预处理 代码通常有点更难读。这可能就是为什么宏发明的原因了。 MarkIf you really want to know if something is a macro or not, you could tryto use the preprocessor of your compiler to get all the macros expanded.You need to be able to call your preprocessor only ofcourse. Read yourcompiler documentation on how to do this.Be prepared to do some searching in the result, because preprocessedcode is usually somewhat harder to read. That''s probably why macros wereinvented.Mark < OT> 只是这一部分你的问题(无论杰克说什么,或者说是否持有b $ b)可能有两种方式 1.因为你使用的是linux(这是最好的)可能意味着您正在使用 gcc),您可以将代码编译为gcc -E以查看后处理器输出。 2.您可以查看使用nm或objdump的符号表。如果你比较 使用宏时的转储,当你不使用时,你可以注意到某些函数出现在转储中很可能是什么 宏扩展到...... < / OT><OT>For just this part of your question (irrespective of what Jack saidheld or not) there could be two ways1. Since you''re using linux (which would most likely mean you''re usinggcc) , 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 comparethe dumps when you use the macro and when you don''t , you can noticesome functions showing up in the dump which are most likely what themacro expands to...</OT> 这篇关于我怎么知道它是一个宏还是实际上是一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!