惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CERT Recently Published Vulnerability Notes
V
Vulnerabilities – Threatpost
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Schneier on Security
Schneier on Security
T
Threatpost
P
Proofpoint News Feed
MongoDB | Blog
MongoDB | Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
大猫的无限游戏
大猫的无限游戏
T
Threat Research - Cisco Blogs
罗磊的独立博客
Security Latest
Security Latest
D
Docker
S
Secure Thoughts
博客园 - 聂微东
A
Arctic Wolf
Recorded Future
Recorded Future
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
P
Palo Alto Networks Blog
Project Zero
Project Zero
Blog — PlanetScale
Blog — PlanetScale
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
T
The Blog of Author Tim Ferriss
Latest news
Latest news
AWS News Blog
AWS News Blog
U
Unit 42
Stack Overflow Blog
Stack Overflow Blog
The GitHub Blog
The GitHub Blog
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
F
Full Disclosure
Martin Fowler
Martin Fowler
T
The Exploit Database - CXSecurity.com
Attack and Defense Labs
Attack and Defense Labs
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
V
V2EX
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
小众软件
小众软件
宝玉的分享
宝玉的分享

博客园 - SPARON

[转] 在 Windows Server 2008 R2 下用 Visual Studio 2010 编译 Chrome 与 WebKit Chromium Port [转]JVM调优总结 6 个基于 HTML5 实现的多媒体播放器 35个五彩缤纷的网页设计作品欣赏 关于setInterval调用对象方法的问题 【收藏】27个jQuery表单插件分享 【收藏】开发人员看过来:11 个免费的开源 IDE Web开发人员应当知道的15个开源项目 终于还是走到了这步! 【转】27 款经典的CSS 框架 如果收购SUN的是Microsoft... CreateFileMapping和MapViewOfFile函数 XP安装 安全补丁KB905414 后本地连接丢失的解决方法 C、CPP const 详解 C语言运算符优先级 详细列表 typedef struct和struct定义结构体的区别 [转]JDK里的设计模式 记CPU的一次复频 C语言字符串转数值
C语言学习之#define用法
SPARON · 2010-12-03 · via 博客园 - SPARON

说到#define大家首先应该想到的是宏定义,对头,但是这有什么问题呢? 

今天在看PG代码的时候发现追溯到深处有些宏定义相当的古怪,比如#define Conn(x,y) x##y,这是什么意思呢?

于是谷歌一下,找到答案:

#define Conn(x,y) x##y 

#define ToChar(x) #@x

#define ToString(x) #x

x##y表示什么?表示x连接y,举例说:

int  n = Conn(123,456);  结果就是n=123456;

char* str = Conn("asdf", "adf"),结果就是 str = "asdfadf"; 

再来看#@x,其实就是给x加上单引号,结果返回是一个const char。举例说:

char a = ToChar(1);结果就是a='1';

做个越界试验char a = ToChar(123);结果是a='3';

但是如果你的参数超过四个字符,编译器就给给你报错了!error C2015: too many characters in constant   :P

最后看看#x,估计你也明白了,他是给x加双引号

char* str = ToString(123132);就成了str="123132";

最后留几个小试验给大家去测测:

#define Dec(x,y) (x-y)

int n = Dec( A(123,1), 1230);

n = Conn(123, Conn(123,332) );

char* str = A("12", ToString( Dec(3,1));

结果会如何呢? 嘿嘿嘿嘿~