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: Sat, 30 May 2015 15:43:24 -0700 Organization: None to speak of Lines: 33 Message-ID: <874mmtk7oz.fsf@kst-u.example.com> References: <032b4cc1-a813-4caa-a810-569e1ea3b0ab@googlegroups.com> <87pp5jjd89.fsf@kst-u.example.com> <04b63e89-57a9-4164-9de2-a4715dc5a8ef@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="24651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19v+4jO9KrIBlE3XfLrrR2o" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:npYm9CQUnHY9hM6tOIBz6QynF+8= sha1:V7rLBecydXhW1YTvnt9RDnD2rmA= Xref: csiph.com comp.lang.c:62859 David Kleinecke writes: > On Friday, May 29, 2015 at 2:17:12 PM UTC-7, Keith Thompson wrote: >> >> I can write: >> >> #define MAX(x, y) ((x) > (y) ? (x) : (y)) >> >> How would you suggest writing that as a parameterless macro? > > Wouldn't > #define MAX_1 x > #define MAX_2 y > #define MAX ((MAX_1) > (MAX_2) ? (MAX_1) : (MAX_2)) > do the same thing? I suppose so. You could also replace functions with parameters by assigning the argument expressions to global variables. Your macro would do the same thing *if* the arguments are literally x and y, but it's much less clear. > But better just write what one means without the macro (an unfair > criticism because you were just writing a simple example). How would you write MAX() without using a macro? The point is that it can take arguments of any type for which ">" is meaningful; a function can't do that. -- 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"