Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370744
  • 博文数量: 66
  • 博客积分: 3201
  • 博客等级: 中校
  • 技术积分: 695
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-04 11:17
文章分类

全部博文(66)

文章存档

2016年(1)

2014年(1)

2012年(1)

2011年(2)

2010年(18)

2009年(42)

2008年(1)

分类: LINUX

2008-11-25 20:46:29

1.3.2 Macro Definitions of Functions
   You might occasionally want to avoid using the macro definition of a
function--perhaps to make your program easier to debug.  There are two
ways you can do this:
   * You can avoid a macro definition in a specific use by enclosing
     the name of the function in parentheses.  This works because the
     name of the function doesn't appear in a syntactic context where
     it is recognizable as a macro call.
   * You can suppress any macro definition for a whole source file by
     using the `#undef' preprocessor directive, unless otherwise stated
     explicitly in the description of that facility.
   For example, suppose the header file `stdlib.h' declares a function
named `abs' with

extern int abs (int);

and also provides a macro definition for `abs'.  Then, in:
    

#include <stdlib.h>
int f (int *i) { return abs (++*i); }

the reference to `abs' might refer to either a macro or a function.  On
the other hand, in each of the following examples the reference is to a
function and not a macro.

#include <stdlib.h>

int g (int *i) { return (abs) (++*i); }
#undef abs
int h (int *i) { return abs (++*i); }

    Since macro definitions that double for a function behave in exactly
the same way as the actual function version, there is usually no need
for any of these methods.  In fact, removing macro definitions usually
just makes your program slower.
阅读(370) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:GNU/Linux application programming

给主人留下些什么吧!~~