emacs-devel
[Top][All Lists]
Advanced

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

Thoughts on replacing macros with static inline functions


From: Brent Pappas
Subject: Thoughts on replacing macros with static inline functions
Date: Mon, 14 Nov 2022 18:05:15 +0000

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); }

The reason why one would want to replace macros with functions is because
functions are often easier to reason about than macros.
The GNU C Preprocessor manual even has a list of pitfalls one can fall into
when programming with macros.
So it may be worthwhile to turn such macros into functions to prevent
developers from accidentally falling into one of these pitfalls.

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


reply via email to

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