首页 | 资讯动态 | linux基础 | 系统管理 | 网络管理 | 编程开发 | linux数据库 | 服务器技术 | linux相关 | linux认证 | 嵌入式 | 下载中心 | 专题 | linux招聘 | 镜像站
OKLinux中文技术站
·设为首页
·加入收藏
·联系我们
系统管理: 中文环境 系统管理 桌面应用 内核技术 | Linux基础: 基础入门 安装配置 常用命令 经验技巧 软件应用 | Linux数据库: Mysql Postgre Oracle DB2 Sybase other
网络管理: 网络安全 网络应用 Linux服务器 环境配置 黑客安全 | 编程开发: PHP CC++ Python Perl Shell 嵌入式开发 java jsp | PHP技术: PHP基础 PHP技巧 PHP应用 PHP文摘
Linux资讯 Linux招聘 Linux专题 Apache | Linux相关: 硬件相关 Linux解决方案 Linux认证 企业应用 其它Unix | 相关下载: 资料下载 参考手册 开发工具 服务器类 软路由 其它
 技术搜索:
会员中心 注册会员 高级搜索  
  → 当前位置:首页>编程开发>cc++>正文

Macro Definitions of Functions

http://www.oklinux.cn  2003-05-01  来源: 互联网  本站整理   会员收藏  游客收藏  【 】 
If we describe something as a function in this manual, it may have a macro definition as well. This normally has no effect on how your program runs--the macro definition does the same thing as the function would. In particular, macro equivalents for library functions evaluate arguments exactly once, in the same way that a function call would. The main reason for these macro definitions is that sometimes they can produce an inline expansion that is considerably faster than an actual function call.

Taking the address of a library function works even if it is also defined as a macro. This is because, in this context, the name of the function isn't followed by the left parenthesis that is syntactically necessary to recognize a macro call.

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.

上一篇:Memory Management (内存管理)   下一篇:Linux程式设计入门


收藏于收藏夹】 【评论】 【推荐】 【打印】 【关闭
相关文档
·Linux程式设计入门
·Memory Management (内存管理)
·Linux 内核模块 和 驱动程序的编写(1)
·Modules
·Networks(网络)
·LINUX C语言开发之2
·LINUX C语言开发之1
·PCI
·PE文件格式详解(1)
·LINUX C语言开发简介
·PE文件格式详解(2)
·Kernel Mechanisms (核心机制)
·PE文件格式详解(3)
·PE文件格式详解(4)
·PE文件格式详解(5)
·PE文件格式详解(6)
发表评论
密码: 匿名评论
评论内容:

(不超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规)
 
  最新文档
·用Eclipse平台进行C/C 开发
·在 Linux 中使用共享对象
·VS:针对Java开发人员的C#编程语言
·使用智能设备扩展在C#中开发自定义控件
·Visual C# 常见问题
·二级C语言实例解答
·一种被忽视的构造和整数溢出重现
·轻轻松松C to C
·与用于 C 的ISO标准保持一致
·用C 的托管扩展针对Windows编程
·运行时和编译时的安全性检查
·轻轻松松C to C (二)
  阅读排行
·c/c++ 学习-read 函数和 write 函数
·程序员眼中的qmail(qmail源代码分析)
·Awk 基础入门:Awk 实例编程
·autoconf 和automake生成Makefile文件
·Linux下的多进程编程
·入门文章:教你学会编写Linux设备驱动
·C++自动化(模板元)编程基础与应用
·使用 GDB 调试多进程程序
·Qt 不规则窗体的实现
·嵌入式程序员应知道的几个基本问题
·Linux操作系统中GCC的应用介绍
·C语言中的指针和内存泄漏
·用GNU profiler提高代码运行速度
·vi 中的正则表达式 (Regular Expressio
·Linux 套接字编程中的 5 个隐患
网摘收藏: