TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

C Preprocessor Hell

46 pointsby emwaover 13 years ago

5 comments

drblastover 13 years ago
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 未加载
ge0rgover 13 years ago
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 未加载
cube13over 13 years ago
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.
kzrdudeover 13 years ago
The ## in front of __VA_ARGS__ is a gcc extension.
评论 #3456111 未加载
ctdonathover 13 years ago
"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 未加载