This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
Re: infra: add CYG_ARRAY_SIZE() macro
- From: David Vrabel <dvrabel at arcom dot com>
- To: Andrew Lunn <andrew at lunn dot ch>
- Cc: eCos Patches <ecos-patches at ecos dot sourceware dot org>
- Date: Wed, 17 May 2006 17:35:52 +0100
- Subject: Re: infra: add CYG_ARRAY_SIZE() macro
- References: <446B4BBB.9030605@arcom.com> <20060517162333.GP14082@lunn.ch>
Andrew Lunn wrote:
> On Wed, May 17, 2006 at 05:13:47PM +0100, David Vrabel wrote:
>> I've had to use something like this quite a bit so I guess it's useful
>> enough to include. It does the same thing as Linux's ARRAY_SIZE macro.
>
> I've always called this NELEM.
That would be a more descriptive name. Have another patch so you can
choose which (if any) to apply.
> Is this defined in any standard anywhere?
I don't think so.
David Vrabel
--
David Vrabel, Design Engineer
Arcom, Clifton Road Tel: +44 (0)1223 411200 ext. 3233
Cambridge CB1 7EA, UK Web: http://www.arcom.com/
Index: ecos-working/packages/infra/current/ChangeLog
===================================================================
--- ecos-working.orig/packages/infra/current/ChangeLog 2006-05-17 16:24:45.000000000 +0100
+++ ecos-working/packages/infra/current/ChangeLog 2006-05-17 16:26:53.000000000 +0100
@@ -1,3 +1,8 @@
+2006-05-17 David Vrabel <dvrabel@arcom.com>
+
+ * include/cyg_type.h: #define CYG_NELEM to calculate the
+ number of elements in a (statically allocated) array.
+
2005-11-04 Bart Veer <bartv@ecoscentric.com>
* tests/cxxsupp.cxx: Fix the compiler warnings.
Index: ecos-working/packages/infra/current/include/cyg_type.h
===================================================================
--- ecos-working.orig/packages/infra/current/include/cyg_type.h 2006-05-17 10:55:22.000000000 +0100
+++ ecos-working/packages/infra/current/include/cyg_type.h 2006-05-17 16:24:06.000000000 +0100
@@ -251,6 +251,11 @@
typedef cyg_haladdrword CYG_ADDRWORD;
// -------------------------------------------------------------------------
+// Number of elements in a (statically allocated) array.
+
+#define CYG_NELEM(a) (sizeof(a) / sizeof((a)[0]))
+
+// -------------------------------------------------------------------------
// Constructor ordering macros. These are added as annotations to all
// static objects to order the constuctors appropriately.