[commit][obv] Use TYPE_LENGTH directly where possible

Jan Kratochvil jan.kratochvil@redhat.com
Fri Sep 28 08:11:00 GMT 2012


On Fri, 28 Sep 2012 06:00:44 +0200, Mark Kettenis wrote:
> > Date: Wed, 26 Sep 2012 12:52:06 +0200
> > From: Joel Brobecker <brobecker@adacore.com>
> > I agree it's subjective. Just FYI, my tolerance starts at 2.  If I need
> > to repeat an expression, I often start thinking about factorizing into
> > constants, functions, etc (duplication is not the only part of the
> > decision process, so I don't necessarily do it).
> 
> I agree with Joel.  Actually my tolerance starts at 1, if it avoids
> having lines that are too long or if it reduces the number of nested
> parentheses to a more manageable level.

In my opinion it cannot be so generalized.  In a larger code using 'len'
variable may be for example less clear because its value may have become stale
after its original 'type' has been updated in the meantime etc.

Anyway thanks for the opinions, personally I do not have opinion on these
differences.

Although I found fine this kind of change (which I pre-approved to Siddhesh as
[obv] according to my opinion):
   ULONGEST val;
-  int len = TYPE_LENGTH (type);

-  if (len <= 4)
+  if (TYPE_LENGTH (type) <= 4)
     {
{ possibly more uses of 'len' }

But I no longer find fine this kind of change contained in this patch:
   int len = TYPE_LENGTH (type);
   ULONGEST c, addr;

-  switch (len)
+  switch (TYPE_LENGTH (type))
     {

because one should not check-in patch which brings the codebase to a state
which is not acceptable as the final solution, which this second case
acceptable is not.


Thanks,
Jan



More information about the Gdb-patches mailing list