[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v1 1/2] [troff]: Add lengthof() macro.
From: |
Alejandro Colomar |
Subject: |
[PATCH v1 1/2] [troff]: Add lengthof() macro. |
Date: |
Fri, 4 Aug 2023 03:00:10 +0200 |
* src/roff/troff/env.cpp (lengthof): Add macro to calculate the number
of elements in an array. It's named after the proposal to ISO C,
_Lengthof(), which wasn't accepted for C23, but hopefully will be
added in a future revision.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
Hi Branden,
I added it there because I didn't find a "common utilities" header file.
Please suggest a better place.
Cheers,
Alex
src/roff/troff/env.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index e0b1b2892..106ab6889 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -33,6 +33,8 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include "input.h"
#include <math.h>
+#define lengthof(arr) (sizeof(arr) / sizeof((arr)[0]))
+
symbol default_family("T");
enum { ADJUST_LEFT = 0,
--
2.40.1
- [PATCH v1 1/2] [troff]: Add lengthof() macro.,
Alejandro Colomar <=
- [PATCH v1 2/2] [troff]: Rewrite function in C., Alejandro Colomar, 2023/08/03
- Re: [PATCH v1 2/2] [troff]: Rewrite function in C., Alejandro Colomar, 2023/08/03
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., G. Branden Robinson, 2023/08/04
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., Alejandro Colomar, 2023/08/04
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., James K. Lowden, 2023/08/07
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., G. Branden Robinson, 2023/08/25
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., Alejandro Colomar, 2023/08/25
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., G. Branden Robinson, 2023/08/26
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., Lennart Jablonka, 2023/08/26
- Re: [PATCH v1 1/2] [troff]: Add lengthof() macro., Alejandro Colomar, 2023/08/26