c++用宏定义来编写函数#define
来源:互联网 发布:出现无法安装java 编辑:程序博客网 时间:2024/06/07 07:10
#include<iostream>#include<stdlib.h>#include<assert.h>#include"hello.h"#ifdef _OPENMP#include<omp.h>#endif#define CHECK(arg){ \ \ cout<<"CHECK:"<<arg<<endl; \}static int _T;#define CHECKOPENMP(arg) \{ \ _T = 10; \}using namespace std;typedef struct Node{ int data; struct Node *lchild; struct Node *rchild;}Node, *BinTree;static ssize_tfun(){ cout<<"fun"<<endl;}int main(int argv,char*argc[]){ register int threadnum = 1; assert(argv-1); #ifdef _OPENMP if(argv > 1){ threadnum = atoi(argc[1]); omp_set_num_threads(threadnum); } #pragma omp parallel for reduction(+:_T) for(int i=0;i<5;i++) _T += i; #endif fun(); CHECK(__FILE__); CHECK(__LINE__); cout<<_T<<endl; CHECKOPENMP(); _CHECK(); cout<<_T<<endl; #ifdef _hello cout<<max(12,14)<<endl; #endif cout<<"Hello World!"<<endl; return 1; }
hello.h如下:
#ifndef _hello#define _helloint max(int a, int b){ return a>b?a:b;}typedef struct cigbsegy{ int a; int b; int c;}cigbsegy, SEGY;#endif#define _CHECK(arg) \{ \ cout<<"_CHECK"<<endl; \}
结果:
rongtao@rongtao:~/test$ g++ -o a hello.cpp -fopenmprongtao@rongtao:~/test$ ./a 3funCHECK:hello.cppCHECK:5410_CHECK1014Hello World!rongtao@rongtao:~/test$
阅读全文
0 0
- c++用宏定义来编写函数#define
- Define()函数来定义常量
- 用定义函数来编写程序
- C宏定义#define
- C语言-#define宏定义
- C-049.宏定义#define
- C语言中的宏定义 #define
- #define定义函数
- c define定义
- C语言里面的内联函数(inline)与宏定义(#define)探讨(转载)
- C语言里面的内联函数(inline)与宏定义(#define)探讨
- C语言里面的内联函数(inline)与宏定义(#define)探讨
- C语言里面的内联函数(inline)与宏定义(#define)探讨
- C语言里面的内联函数(inline)与宏定义(#define)探讨
- C语言中的内联函数(inline)与宏定义(#define)详细解析
- C语言中的内联函数(inline)与宏定义(#define)详细解析
- C语言中的内联函数(inline)与宏定义(#define)详细解析
- linux c之使用#define定义多行函数总结
- OD操作整理-API断点的设置;寄存器的修改;数据的查看
- python自学笔记1
- 全面解读流程图|附共享单车摩拜ofo案例分析
- java策略模式
- 第19节项目5-我的加班费
- c++用宏定义来编写函数#define
- 学习笔记8
- linux常用命令
- phpQuery和simple_html_dom DOM解析器对比
- Spring-Cloud中通过Feign调用外网HTTP网络通信方法
- Hystrix生产环境线程池自动扩容与缩容的动态资源分配经验
- 八个维度,谈谈产品经理的分类与发展方向
- Android样式 layer-list
- 杭电acm P2004成绩转换