bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## Re: return'ing a struct and trap representations

 From: Ralf Wildenhues Subject: Re: return'ing a struct and trap representations Date: Fri, 22 Sep 2006 19:15:10 +0200 User-agent: Mutt/1.5.13 (2006-08-11)

```Hello Bruno,

* Bruno Haible wrote on Fri, Sep 22, 2006 at 05:31:08PM CEST:
> > > However, for integer and pointer types there are "trap representations".
>
> Should be: for integer and pointer types there are _no_ "trap
> representations".

I don't think that is guaranteed by C99.  Quoting 6.2.6.2(2):

| For signed integer types, the bits of the object representation shall
| be divided into three groups: value bits, padding bits, and the sign
| bit. There need not be any padding bits; there shall be exactly one
| sign bit. Each bit that is a value bit shall have the same value as
| the same bit in the object representation of the corresponding
| unsigned type (if there are M value bits in the signed type and N in
| the unsigned type, then M   N).  If the sign bit is zero, it shall not
| affect the resulting value.  If the sign bit is one, the value shall
| be modified in one of the following ways:
| - the corresponding value with sign bit 0 is negated (sign and magnitude);
| - the sign bit has the value -(2N) (two's complement);
| - the sign bit has the value -(2N - 1) (one's complement).
| Which of these applies is implementation-defined, as is whether the
| value with sign bit 1 and all value bits zero (for the first two), or
| with sign bit and all value bits 1 (for one's complement), is a trap
| representation or a normal value.  In the case of sign and magnitude
| and one's complement, if this representation is a normal value it is
| called a negative zero.

Certainly the practical value of this for gnulib is questionable.

> > Do you think it would be useful to add debug code to
> > initialize them (guarded by some preprocessor define that evaluates to 0
> > by default)?
>
> This would be ok, yes. The processor define that other files already
> use for this purpose is
>      #ifdef lint

That's good enough for me.  I've applied this patch.  Thanks for the
review!

Cheers,
Ralf

* gl_anylinked_list2.h [lint] (gl_linked_iterator)
(gl_linked_iterator_from_to): Initialize struct completely.
* gl_anytree_list2.h [lint] (gl_tree_iterator): Likewise.
(gl_tree_iterator_from_to): Likewise
* gl_anytree_oset.h [lint] (gl_tree_iterator): Likewise.
* gl_array_list.c [lint] (gl_array_iterator)
(gl_array_iterator_from_to): Likewise.
* gl_array_oset.c [lint] (gl_array_iterator): Likewise.
* gl_carray_list.c [lint] (gl_carray_iterator)
(gl_carray_iterator_from_to): Likewise.

Index: lib/gl_anylinked_list2.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gl_anylinked_list2.h,v
retrieving revision 1.2
diff -u -r1.2 gl_anylinked_list2.h
--- lib/gl_anylinked_list2.h    24 Jul 2006 16:34:38 -0000      1.2
+++ lib/gl_anylinked_list2.h    22 Sep 2006 17:12:31 -0000
@@ -697,6 +697,11 @@
result.list = list;
result.p = list->root.next;
result.q = &list->root;
+#ifdef lint
+  result.i = 0;
+  result.j = 0;
+  result.count = 0;
+#endif

return result;
}
@@ -763,6 +768,12 @@
result.q = node;
}

+#ifdef lint
+  result.i = 0;
+  result.j = 0;
+  result.count = 0;
+#endif
+
return result;
}

Index: lib/gl_anytree_list2.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gl_anytree_list2.h,v
retrieving revision 1.1
diff -u -r1.1 gl_anytree_list2.h
--- lib/gl_anytree_list2.h      17 Jul 2006 11:27:18 -0000      1.1
+++ lib/gl_anytree_list2.h      22 Sep 2006 17:12:31 -0000
@@ -349,6 +349,11 @@
result.p = node;
/* End point is past the rightmost node.  */
result.q = NULL;
+#ifdef lint
+  result.i = 0;
+  result.j = 0;
+  result.count = 0;
+#endif

return result;
}
@@ -368,6 +373,11 @@
result.p = (start_index < count ? node_at (list->root, start_index) : NULL);
/* End point is the node at position end_index.  */
result.q = (end_index < count ? node_at (list->root, end_index) : NULL);
+#ifdef lint
+  result.i = 0;
+  result.j = 0;
+  result.count = 0;
+#endif

return result;
}
Index: lib/gl_anytree_oset.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gl_anytree_oset.h,v
retrieving revision 1.1
diff -u -r1.1 gl_anytree_oset.h
--- lib/gl_anytree_oset.h       17 Jul 2006 11:27:35 -0000      1.1
+++ lib/gl_anytree_oset.h       22 Sep 2006 17:12:31 -0000
@@ -211,6 +211,11 @@
result.p = node;
/* End point is past the rightmost node.  */
result.q = NULL;
+#ifdef lint
+  result.i = 0;
+  result.j = 0;
+  result.count = 0;
+#endif

return result;
}
Index: lib/gl_array_list.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gl_array_list.c,v
retrieving revision 1.2
diff -u -r1.2 gl_array_list.c
--- lib/gl_array_list.c 14 Sep 2006 14:18:36 -0000      1.2
+++ lib/gl_array_list.c 22 Sep 2006 17:12:31 -0000
@@ -394,6 +394,10 @@
result.count = list->count;
result.p = list->elements + 0;
result.q = list->elements + list->count;
+#ifdef lint
+  result.i = 0;
+  result.j = 0;
+#endif

return result;
}
@@ -411,6 +415,10 @@
result.count = list->count;
result.p = list->elements + start_index;
result.q = list->elements + end_index;
+#ifdef lint
+  result.i = 0;
+  result.j = 0;
+#endif

return result;
}
Index: lib/gl_array_oset.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gl_array_oset.c,v
retrieving revision 1.2
diff -u -r1.2 gl_array_oset.c
--- lib/gl_array_oset.c 14 Sep 2006 14:18:36 -0000      1.2
+++ lib/gl_array_oset.c 22 Sep 2006 17:12:31 -0000
@@ -229,6 +229,10 @@
result.count = set->count;
result.p = set->elements + 0;
result.q = set->elements + set->count;
+#ifdef lint
+  result.i = 0;
+  result.j = 0;
+#endif

return result;
}
Index: lib/gl_carray_list.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gl_carray_list.c,v
retrieving revision 1.2
diff -u -r1.2 gl_carray_list.c
--- lib/gl_carray_list.c        14 Sep 2006 14:18:36 -0000      1.2
+++ lib/gl_carray_list.c        22 Sep 2006 17:12:31 -0000
@@ -528,6 +528,10 @@
result.count = list->count;
result.i = 0;
result.j = list->count;
+#ifdef lint
+  result.p = 0;
+  result.q = 0;
+#endif

return result;
}
@@ -545,6 +549,10 @@
result.count = list->count;
result.i = start_index;
result.j = end_index;
+#ifdef lint
+  result.p = 0;
+  result.q = 0;
+#endif

return result;
}

```

reply via email to

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