This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fixinc Patch to deprecate casts as lvalues for C


"Joseph S. Myers" wrote:

> The trouble with making a comprehensible fix is that (a) the original
> obstack.h code is rather cryptic (this extension in general is) and (b)
> it's not just one place in obstack.h that needs fixing, but several
> (though only one triggers in a bootstrap of GCC).  All the places - in the
> version of obstack.h I looked at - are of the form
> 
>   *((TYPE*)X)++ = (Y)
> 
> which I want to change into
> 
>   ((*((TYPE*)X) = (Y)), (X += sizeof (TYPE)))
> 
> (correct for the uses in obstack.h, not for all possible uses of lvalue
> casts matching this pattern).  If this effect can be achieved more
> comprehensibly, feel free to rewrite the fix accordingly.

Oh, I wasn't meaning to criticize your attempt as being a poor
attempt.  Rather simply that it is hard to understand.  It is.
It is a consequence of having to match regex grouping characters
'(', ')' and '*' and use grouping yourself.  You did a great job.
It just makes my head hurt.  :-}  Now that I've seen your comment
above, the one suggestion I'd make is to add a comment a la:

/*
 *  We need to change assign & increment pointer casts from this:
 *
 *     *((TYPE*)PTRVAR1)++ = (PTRVAR2)
 *
 *  into expressions like this:
 *
 *     ((*((TYPE*)PTRVAR1) = (PTRVAR2)), (PTRVAR1 += sizeof (TYPE)))
 *
 *  because ``*((TYPE*)PTRVAR1)'' is not always legal l-value.
 */

Cheers - Bruce


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]