在 C 中使用双哈希 (##) [英] Use of double hash (##) in C
本文介绍了在 C 中使用双哈希 (##)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
头文件 cissvar.h 有这样的定义:
header file cissvar.h has this definition:
#define CISSQ_REQUEST_QUEUE(name, index)
static __inline void
ciss_initq_ ## name (struct ciss_softc *sc)
{
STAILQ_INIT(&sc->ciss_ ## name);
CISSQ_INIT(sc, index);
}
(...)
ciss.c 看起来像这样:
ciss_initq_free(sc);
ciss_initq_notify(sc);
如果有人能解释这是如何工作的,那就太好了.
It would be great if someone can explain how does this work.
所以,
- name 指的是免费";或通知"
- 索引"在哪里?来自哪里?
- 编译器如何在此处实现 .h 和 .c 之间的魔法绑定?
推荐答案
重要的几行是这些(也在 cissvar.h 中):
The important lines are these (also in cissvar.h):
CISSQ_REQUEST_QUEUE(free, CISSQ_FREE);
CISSQ_REQUEST_QUEUE(notify, CISSQ_NOTIFY);
他们调用您粘贴的那个宏.##"运算符将两个代码单词连接成一个单词,因此为第一行生成的代码(使用宏扩展)如下所示:
They invoke that macro that you pasted. The "##" operator concatenates two words of code together into a single word, so the code generated (with the macro expansion) for the first line looks something like this:
static __inline void
ciss_initq_free(struct ciss_softc *sc)
{
STAILQ_INIT(&sc->ciss_free);
CISSQ_INIT(sc, CISSQ_FREE);
}
这篇关于在 C 中使用双哈希 (##)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文