[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] obstack uses casts as lvalues
From: |
Paul Eggert |
Subject: |
Re: [Bug-gnulib] obstack uses casts as lvalues |
Date: |
21 Oct 2003 13:45:04 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
"Joseph S. Myers" <address@hidden> writes:
> GCC is removing the casts-as-lvalues extension (to be removed for C++ in
> GCC 3.4, deprecated for C in 3.4 and removed for C in 3.5). obstack.h
> uses this extension; this patch removes those uses I know of.
I see a couple of other instances of lvalue casts, in the non-GCC part
of obstack.h. Weird. Perhaps these macros are never really used?
What do you think of the idea of replacing (*((T *) p)++ = e) with
(*(*(T **) &p)++ = e) instead? That would be simpler than the
patch you proposed, which replaced it with (*(T *) p = e, p += sizeof e).
Something like this (which I haven't tested):
Index: obstack.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/obstack.h,v
retrieving revision 1.23
diff -p -u -r1.23 obstack.h
--- obstack.h 9 Sep 2003 23:00:43 -0000 1.23
+++ obstack.h 21 Oct 2003 20:42:27 -0000
@@ -276,6 +276,12 @@ extern int obstack_exit_failure;
#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar)
+#define obstack_ptr_grow_fast(h,aptr) \
+ (*(*(const void ***) &(h)->next_free)++ = (aptr))
+
+#define obstack_int_grow_fast(h,aint) \
+ (*(*(int **) &(h)->next_free)++ = (aint))
+
#define obstack_blank_fast(h,n) ((h)->next_free += (n))
#define obstack_memory_used(h) _obstack_memory_used (h)
@@ -354,7 +360,7 @@ __extension__
\
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
_obstack_newchunk (__o, sizeof (void *)); \
- *((void **)__o->next_free)++ = (datum); \
+ *(*(const void ***) &__o->next_free)++ = (datum); \
(void) 0; })
# define obstack_int_grow(OBSTACK,datum) \
@@ -362,15 +368,9 @@ __extension__
\
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + sizeof (int) > __o->chunk_limit) \
_obstack_newchunk (__o, sizeof (int)); \
- *((int *)__o->next_free)++ = (datum); \
+ *(*(int **) &__o->next_free)++ = (datum); \
(void) 0; })
-# define obstack_ptr_grow_fast(h,aptr) \
- (*((void **) (h)->next_free)++ = (aptr))
-
-# define obstack_int_grow_fast(h,aint) \
- (*((int *) (h)->next_free)++ = (aint))
-
# define obstack_blank(OBSTACK,length) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
@@ -469,18 +469,12 @@ __extension__
\
# define obstack_ptr_grow(h,datum) \
( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
- (*((const char **) (((h)->next_free+=sizeof(char *))-sizeof(char *))) =
(datum)))
+ (*(*(const void ***) &(h)->next_free)++ = (datum)))
# define obstack_int_grow(h,datum) \
( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
- (*((int *) (((h)->next_free+=sizeof(int))-sizeof(int))) = (datum)))
-
-# define obstack_ptr_grow_fast(h,aptr) \
- (*((const char **) (h)->next_free)++ = (aptr))
-
-# define obstack_int_grow_fast(h,aint) \
- (*((int *) (h)->next_free)++ = (aint))
+ (*(*(int **) &(h)->next_free)++ = (datum)))
# define obstack_blank(h,length) \
( (h)->temp = (length),
\