为什么kfifo.h充满#define语句 [英] Why is kfifo.h so full of #define statements

查看:264
本文介绍了为什么kfifo.h充满#define语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

kfifo。 ^ h 由几乎完全的#define 的。这是为什么?他们为什么没有宣布在H文件中像它的正常完成的功能。

kfifo.h is made up almost entirely of #define. Why is that? Why have they not declared the functions in the h file like its "normally" done.

好像我的问题是PTED作为实现的质疑轻易间$ P $,而不是我彪问,这是为什么实现好,从学习的角度来看。无论如何,因为我不知道我在看函数宏我投票关闭,因为它是obviosly重复。

It seems like my question is easily interpreted as a questioning of the implementation rather than what I ment to ask, why is this implementation better, from a learning standpoint. Anyway, since I didn't know I was looking at "Function-like macros" I am voting to close since it's obviosly a duplicate.

推荐答案

这是允许有很多的宏。为什么那麻烦你了?

It is permitted to have a lot of macros. Why does that trouble you?

 #define STRUCT_KFIFO_PTR(type) \
   struct __STRUCT_KFIFO_PTR(type, 0, type)

不是一个函数宏。

is not a function-like macro.

 #define kfifo_initialized(fifo) ((fifo)->kfifo.mask)

也可以用于某些任务(即使你可能不应该这样做)的左侧。它是短于相应的在线函数写

 static inline unsigned kfifo_initialezed_f(struct __kfifo *fifo) {
    return fifo->kfifo.mask;
 }

和更重要的是宏观 kfifo_initialized 将其 FIFO的几个不同的申报工作实际的参数(这是通用在一些有限的意义上)。

and more importantly the macro kfifo_initialized would work with several different declarations of its fifo actual argument (it is "generic" in some limited sense).

 #define __STRUCT_KFIFO(type, size, recsize, ptrtype) \
    { \
   __STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \
        type    buf[((size < 2) || (size & (size - 1))) ? -1 : size]; \
    }

将扩大到申报相当于一个数组 BUF [-1] 如果给一个尺寸 3 键,这将使编译器吆喝。 (最近的C ++标准2011还具有 static_assert 等用途)。

would expand to a declaration equivalent to an array buf[-1] if given a size of 3 and that would make the compiler yell. (The recent C++2011 standard also has static_assert for such purposes).

所以我不明白为什么你感到吃惊。在 C 的preprocessor是非常有用的(恕我直言,这甚至不够强大)。为什么要避免使用它?

So I don't understand why you are surprised. The C preprocessor is useful (IMHO it is even not powerful enough). Why avoid using it?

这是<强>免费软件;如果你不喜欢这样的源文件,你可以工作,提高它(这将需要时间)提出一个更好的解决方案。我不喜欢现在的这个。

This is free software; if you don't like that source file, you could work to improve it (and that would take time) to propose a better solution. I do like the current one.

这篇关于为什么kfifo.h充满#define语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆