博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C语言中命名空间的实现
阅读量:4361 次
发布时间:2019-06-07

本文共 1423 字,大约阅读时间需要 4 分钟。

 

foobar.h

1 // inclusion guard 2 #ifndef FOOBAR_H_ 3 #define FOOBAR_H_ 4  5 //// long names 6 //int foobar_some_func(int); 7 //void foobar_other_func(); 8 int some_func(int); 9 void other_func();10 11 // short names12 #ifdef NAMESPACE foobar13 #define some_func(...) foobar_some_func(__VA_ARGS__)14 #define other_func(...) foobar_other_func(__VA_ARGS__)15 #endif16 17 #endif

 

foobar.c

1 #define NAMESPACE foobar 2  3 #include "stdio.h" 4 #include "foobar.h" 5  6  7  8  9 int some_func(int a)10 {11     return a + 99;12 }

 

goobar.h

1 // inclusion guard 2 #ifndef GOOBAR_H_ 3 #define GOOBAR_H_ 4  5 //// long names 6 //int foobar_some_func(int); 7 //void foobar_other_func(); 8  9 // short names10 #ifdef NAMESPACE goobar11 #define some_func(...) goobar_some_func(__VA_ARGS__)12 #define other_func(...) goobar_other_func(__VA_ARGS__)13 #endif14 15 #endif

 

goobar.c

1 #define NAMESPACE goobar 2 #include "stdio.h" 3 #include "goobar.h" 4  5  6  7  8 int some_func(int a) 9 {10     return a + 8;11 }

 

main.c

1 #define NAMESPACE goobar 2 #define NAMESPACE foobar 3  4  5 #include "stdio.h" 6  7 #include "goobar.h" 8 #include "foobar.h" 9 10 11 //http://stackoverflow.com/questions/389827/namespaces-in-c12 void main()13 {14     int val = goobar_some_func(12);15     printf("value = %d\n", val);16 17     val = some_func(12);18     printf("value = %d\n", val);19 20     return;21 }

 

 

转载于:https://www.cnblogs.com/yasepix/p/5084668.html

你可能感兴趣的文章
Windows下VMware14黑屏
查看>>
Nginx解析PHP
查看>>
PHP之选择排序法
查看>>
beego小技巧两则:通过命令行自定义端口和环境,url中带有中划线处理
查看>>
在k8s集群中,利用prometheus的jmx_exporter进行tomcat的JVM性能监控,并用grafana作前端展示...
查看>>
伤透了心的pytorch的cuda容器版
查看>>
MYSQL的硬盘IO过高引起的CPU过高判断
查看>>
PYTHON多进程样码
查看>>
JDBC插入数据超长时无法自动截断问题
查看>>
javascript之,深扒typeof,instanceof操作符
查看>>
18.1 C语言编程集锦
查看>>
node.js安装使用express框架
查看>>
Daily Scrum 1/7/2015
查看>>
leetcode 15.三数之和
查看>>
数据结构(二)栈与队列---栈的应用:四则运算实现
查看>>
自定义Notification实现例子
查看>>
已知空间三个点,解算外接圆圆心坐标,C++编程实现
查看>>
Android上HDMI介绍(基于高通平台)
查看>>
Python 时间复杂度
查看>>
Kubernetes 学习6 Pod控制器应用进阶
查看>>