[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?
- Thoughts on replacing macros with static inline functions,
Brent Pappas <=
- Re: Thoughts on replacing macros with static inline functions, Eli Zaretskii, 2022/11/15
- Re: Thoughts on replacing macros with static inline functions, Richard Stallman, 2022/11/18
- Re: Thoughts on replacing macros with static inline functions, xenodasein, 2022/11/18
- Re: Thoughts on replacing macros with static inline functions, Po Lu, 2022/11/18
- Re: Thoughts on replacing macros with static inline functions, xenodasein, 2022/11/18
- Re: Thoughts on replacing macros with static inline functions, Po Lu, 2022/11/18
- Re: Thoughts on replacing macros with static inline functions, Eli Zaretskii, 2022/11/18
- Re: Thoughts on replacing macros with static inline functions, xenodasein, 2022/11/18
- Re: Thoughts on replacing macros with static inline functions, Po Lu, 2022/11/18
- Re: Thoughts on replacing macros with static inline functions, Eli Zaretskii, 2022/11/18