Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Making C more beautiful by not using macros with arguments Date: Fri, 29 May 2015 14:16:54 -0700 Organization: None to speak of Lines: 52 Message-ID: <87pp5jjd89.fsf@kst-u.example.com> References: <032b4cc1-a813-4caa-a810-569e1ea3b0ab@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="22413"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RD4h1AXazcsPqY+6cmU71" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:R4v+0b0Q3xg5m/Ut1w5LZKUZbG0= sha1:WshxTNbiZqrnuaQ+vc9MzorHy80= Xref: csiph.com comp.lang.c:62810 David Kleinecke writes: > In the world of C90 at least. > > I think everybody knows that if I were defining a macro with > arguments I must leave no spaces between the macro name and > the following opening parenthesis. Right -- though it's important to note that this requirement doesn't apply to invocations of function-like macros. > I think everybody who has contemplated this fact will agree that is > is the ugliest thing in C. I cit myself as one more counterexample of your claim. I haven't taken the time to decide what the ugliest thing in C is, but this isn't it. Off the top of my head, I consider trigraphs, multi-character constants, and the implementation-defined signedness of plain char to be uglier. YMMV. [...] > This "improvement" - if it actually works - is easy to implement - > just stop writing macros with arguments. The standard assert() macro cannot be defined as a parameterless macro. If it were, then assert(expr); would always evalute expr whether NDEBUG is defined or not. I routinely use function-like macros for logging. The macro definitions depend on compile-time flags, and expand to different code depending on the logging level. They could not be written correctly as parameterless macros; the argument would always be evaluated. Standard library functions are permitted to be additionally defined as function-like macros. Defining them as parameterless macros would not permit bypassing any macro definition by enclosing the function name in parentheses. (That's in section 7 of the standard.) I can write: #define MAX(x, y) ((x) > (y) ? (x) : (y)) How would you suggest writing that as a parameterless macro? -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"