了解 Linux 内核中的 #define #ifdef 和宏
我刚刚开始审计 Linux 内核,我不禁注意到源代码中大量的 #defines 和 #ifdef。我似乎无法准确理解这些是如何使用的。我查过网络,但我发现的描述似乎非常模糊。任何人都可以告诉我 #defines 等到底做什么以及为什么使用它们吗?我现在只需要一个简短的解释。
此外,人们在我看过的不同来源上经常谈论宏。我完全不知道他们在说什么,而且和以前一样,我在网上找到的任何描述都同样神秘。有人可以向我解释一下宏吗?它们是如何定义的以及为什么它们在 Linux 内核中如此频繁地使用(显然据我所知)。
任何帮助将不胜感激。
I have just started work on auditing the Linux kernel and I cant help but notice in the source code the multitude of #defines and #ifdefs. I cant seem to understand exactly how these are being used. I have checked the web but the descriptions I have found seem awfully vague. Can any one enlighten me as to what exactly #defines and the like do and why they are used? A brief explanation is all I need for now.
Further more, people speak of macros a lot on different sources I have looked at. I have absolutely no clue what they are talking about and again as before any description I have found on the web have been equally as cryptic. Can someone please explain macros to me? How they are defined and why they are used so frequently (apparently for all I know) in the Linux kernel.
Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我进一步研究了之前的问题,发现我需要研究 C 预处理器来寻找答案。一位讲师提到预处理器扩展了宏,所以我跟进了。这是其他对宏背后的含义感兴趣的人的链接等。 c 预处理器
希望它能帮助其他迷失的灵魂:)
I looked further into my previous question and found that I needed to look into the C preprocessor for the answer. A lecturer menutioned that the preprocessor expands the macros and so I followed it up. Here is the link for anyone else interested into the meaning behind macros etc. the c preprocessor
hope it helps some other lost soul :)