all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Thoughts on replacing macros with static inline functions
@ 2022-11-14 18:05 Brent Pappas
  2022-11-15 12:45 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Brent Pappas @ 2022-11-14 18:05 UTC (permalink / raw)
  To: emacs-devel@gnu.org

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?


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-11-18 16:16 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-14 18:05 Thoughts on replacing macros with static inline functions Brent Pappas
2022-11-15 12:45 ` Eli Zaretskii
2022-11-18  5:05   ` Richard Stallman
2022-11-18  6:19     ` xenodasein--- via Emacs development discussions.
2022-11-18  6:27       ` Po Lu
2022-11-18  6:32         ` xenodasein--- via Emacs development discussions.
2022-11-18  7:29           ` Po Lu
2022-11-18  8:34         ` Eli Zaretskii
2022-11-18 11:31           ` xenodasein--- via Emacs development discussions.
2022-11-18 11:43             ` Po Lu
2022-11-18 12:00             ` Eli Zaretskii
2022-11-18  6:59       ` tomas
2022-11-18  7:12         ` xenodasein--- via Emacs development discussions.
2022-11-18 14:53       ` Stefan Monnier
2022-11-18 16:16         ` Dr. Arne Babenhauserheide
2022-11-15 13:49 ` Po Lu
2022-11-15 15:54   ` xenodasein--- via Emacs development discussions.
2022-11-15 14:10 ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.