emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Thoughts on replacing macros with static inline functions


From: Po Lu
Subject: Re: Thoughts on replacing macros with static inline functions
Date: Tue, 15 Nov 2022 21:49:14 +0800
User-agent: Gnus/5.13 (Gnus v5.13)

Brent Pappas <pappasbrent@Knights.ucf.edu> writes:

> Title: Thoughts on replacing macros with static inline functions
>
> Hi,
>
> I noticed that Emacs code sometimes uses macros where a static inline function
> would appear to work equally as well.
> For instance, consider the macro PAD defined in src/xsettings.c
>
> #define PAD(nr)    (((nr) + 3) & ~3)
>
> I imagine this could be turned into a function like so:
>
> static inline int PAD(int nr)    { return (((nr) + 3) & ~3); }

I find that rather ugly.  PAD is an example of an extremely trivial
expression that should really be a macro.

> How interested would the Emacs community be in porting macros to functions?

Not very, in this case.  That exact PAD macro is not only an idiom used
throughout the Emacs X11 code, it is more-or-less an idiom of the entire
X Window System, copied around and used extensively throughout the X
sample server, Xlib, and C-language clients.

In addition, we try to avoid undue changes to working code, so giving
carte blanche to change macros to static functions is not something we
really want to do.  But if you want to do that to a few big, ugly,
macros around an area in which you are making actual changes, please go
ahead.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]