Added G_N_ELEMENTS macro to determine the number of elements in an array.
authorOwen Taylor <otaylor@redhat.com>
Fri, 21 Jan 2000 15:27:39 +0000 (15:27 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Fri, 21 Jan 2000 15:27:39 +0000 (15:27 +0000)
Fri Jan 21 10:18:24 2000  Owen Taylor  <otaylor@redhat.com>

* glib.h (G_N_ELEMENTS): Added G_N_ELEMENTS macro to determine
the number of elements in an array.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib.h
glib/glib.h

index ef72dca..8731bf1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Jan 21 10:18:24 2000  Owen Taylor  <otaylor@redhat.com>
+
+       * glib.h (G_N_ELEMENTS): Added G_N_ELEMENTS macro to determine
+       the number of elements in an array.
+
 Sun Jan  9 13:28:36 2000  Tim Janik  <timj@gtk.org>
 
        * gstrfuncs.c (g_strtod): correctly fetch the current locale,
index ef72dca..8731bf1 100644 (file)
@@ -1,3 +1,8 @@
+Fri Jan 21 10:18:24 2000  Owen Taylor  <otaylor@redhat.com>
+
+       * glib.h (G_N_ELEMENTS): Added G_N_ELEMENTS macro to determine
+       the number of elements in an array.
+
 Sun Jan  9 13:28:36 2000  Tim Janik  <timj@gtk.org>
 
        * gstrfuncs.c (g_strtod): correctly fetch the current locale,
index ef72dca..8731bf1 100644 (file)
@@ -1,3 +1,8 @@
+Fri Jan 21 10:18:24 2000  Owen Taylor  <otaylor@redhat.com>
+
+       * glib.h (G_N_ELEMENTS): Added G_N_ELEMENTS macro to determine
+       the number of elements in an array.
+
 Sun Jan  9 13:28:36 2000  Tim Janik  <timj@gtk.org>
 
        * gstrfuncs.c (g_strtod): correctly fetch the current locale,
index ef72dca..8731bf1 100644 (file)
@@ -1,3 +1,8 @@
+Fri Jan 21 10:18:24 2000  Owen Taylor  <otaylor@redhat.com>
+
+       * glib.h (G_N_ELEMENTS): Added G_N_ELEMENTS macro to determine
+       the number of elements in an array.
+
 Sun Jan  9 13:28:36 2000  Tim Janik  <timj@gtk.org>
 
        * gstrfuncs.c (g_strtod): correctly fetch the current locale,
index ef72dca..8731bf1 100644 (file)
@@ -1,3 +1,8 @@
+Fri Jan 21 10:18:24 2000  Owen Taylor  <otaylor@redhat.com>
+
+       * glib.h (G_N_ELEMENTS): Added G_N_ELEMENTS macro to determine
+       the number of elements in an array.
+
 Sun Jan  9 13:28:36 2000  Tim Janik  <timj@gtk.org>
 
        * gstrfuncs.c (g_strtod): correctly fetch the current locale,
index ef72dca..8731bf1 100644 (file)
@@ -1,3 +1,8 @@
+Fri Jan 21 10:18:24 2000  Owen Taylor  <otaylor@redhat.com>
+
+       * glib.h (G_N_ELEMENTS): Added G_N_ELEMENTS macro to determine
+       the number of elements in an array.
+
 Sun Jan  9 13:28:36 2000  Tim Janik  <timj@gtk.org>
 
        * gstrfuncs.c (g_strtod): correctly fetch the current locale,
index ef72dca..8731bf1 100644 (file)
@@ -1,3 +1,8 @@
+Fri Jan 21 10:18:24 2000  Owen Taylor  <otaylor@redhat.com>
+
+       * glib.h (G_N_ELEMENTS): Added G_N_ELEMENTS macro to determine
+       the number of elements in an array.
+
 Sun Jan  9 13:28:36 2000  Tim Janik  <timj@gtk.org>
 
        * gstrfuncs.c (g_strtod): correctly fetch the current locale,
index ef72dca..8731bf1 100644 (file)
@@ -1,3 +1,8 @@
+Fri Jan 21 10:18:24 2000  Owen Taylor  <otaylor@redhat.com>
+
+       * glib.h (G_N_ELEMENTS): Added G_N_ELEMENTS macro to determine
+       the number of elements in an array.
+
 Sun Jan  9 13:28:36 2000  Tim Janik  <timj@gtk.org>
 
        * gstrfuncs.c (g_strtod): correctly fetch the current locale,
diff --git a/glib.h b/glib.h
index b94c945..92397dd 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -134,6 +134,11 @@ extern "C" {
 #define G_STRINGIFY(macro_or_string)   G_STRINGIFY_ARG (macro_or_string)
 #define        G_STRINGIFY_ARG(contents)       #contents
 
+/* Count the number of elements in an array. The array must be defined
+ * as such; using this with a dynamically allocated array will give
+ * incorrect results.
+ */
+#define G_N_ELEMENTS(arr)              (sizeof(arr) / sizeof((arr)[0]))
 
 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
  * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
index b94c945..92397dd 100644 (file)
@@ -134,6 +134,11 @@ extern "C" {
 #define G_STRINGIFY(macro_or_string)   G_STRINGIFY_ARG (macro_or_string)
 #define        G_STRINGIFY_ARG(contents)       #contents
 
+/* Count the number of elements in an array. The array must be defined
+ * as such; using this with a dynamically allocated array will give
+ * incorrect results.
+ */
+#define G_N_ELEMENTS(arr)              (sizeof(arr) / sizeof((arr)[0]))
 
 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
  * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.