Showing content from https://lists.gnu.org/archive/html/emacs-devel/2022-11/msg00869.html below:
Thoughts on replacing macros with static inline functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] 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
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4