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

推荐订阅源

P
Privacy & Cybersecurity Law Blog
V
V2EX
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
Kaspersky official blog
S
Secure Thoughts
T
Tenable Blog
Security Latest
Security Latest
The Cloudflare Blog
S
Security @ Cisco Blogs
H
Heimdal Security Blog
aimingoo的专栏
aimingoo的专栏
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
IT之家
IT之家
Latest news
Latest news
The Hacker News
The Hacker News
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
N
News | PayPal Newsroom
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
S
Security Affairs
S
Securelist
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
A
About on SuperTechFans

博客园 - 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));

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