groff
[Top][All Lists]
Advanced

[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




reply via email to

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