TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

C Preprocessor Hell

46 点作者 emwa超过 13 年前

5 条评论

drblast超过 13 年前
I don't know why people don't seem to think of this when confronted with the limitations of the standard C preprocessor, but Perl or Lisp both make excellent C preprocessors.<p>You aren't required to only use the C source code transformation tools that a default install of GCC provides.
评论 #3457247 未加载
评论 #3457199 未加载
评论 #3456790 未加载
评论 #3456813 未加载
评论 #3456804 未加载
评论 #3456830 未加载
ge0rg超过 13 年前
The code in the article is actually less horrible than I expected from the title. However, it seems like a situation which could be more elegantly solved with X-Macros (<a href="http://drdobbs.com/cpp/184401387" rel="nofollow">http://drdobbs.com/cpp/184401387</a>), provided that you consider X-Macros elegant.<p><i>X-Macros: you have a header file consisting of lines in the form of "FOO(name, type, defvalue);" and include it several times with different definitions for FOO.</i>
评论 #3456349 未加载
cube13超过 13 年前
Why not just make an internal API function? In my experience with high performance, multiplatform C, macro usage is usually the last thing we do. Macros are absolutely horrendous to debug, and tends to lead to less readable code. They're useful to alias specific platform implementations to a standard interface, or for tiny functions that absolutely need to be inlined for performance.<p>In this specific case, it might make more sense to have the programmer tell you how many arguments to expect and work with it that way, rather than going through this chain of macros. C doesn't allow function arguments to change dynamically, so that might be a slightly better approach. It would be easier to understand, but a bit harder to maintain code that uses it.
kzrdude超过 13 年前
The ## in front of __VA_ARGS__ is a gcc extension.
评论 #3456111 未加载
ctdonath超过 13 年前
"Lisp programmers should stop reading right now because they'll likely suffer severe injury of the jaw muscles as they laugh themselves silly at how hard it is to do some things in C."<p>Naive question: in Lisp, how would you set the byte at address 0xDEADBEEF to 0x42?
评论 #3456889 未加载
评论 #3459800 未加载
评论 #3457155 未加载