subversion-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Stein <gst...@gmail.com>
Subject Re: Review of sizeof usage
Date Wed, 12 Aug 2015 02:47:49 GMT
On Tue, Aug 11, 2015 at 2:55 PM, Branko ─îibej <brane@wandisco.com> wrote:

> On 11.08.2015 17:02, Philip Martin wrote:
> > Stefan Fuhrmann <stefan.fuhrmann@wandisco.com> writes:
> >
> >> way we use sizeof. In my opinion, we should take the
> >> size of the created or processed variable instead of its
> >> type, i.e.
> >>
> >>   abc_t *v = apr_pcalloc(pool, sizeof(*v));
> >>   apr_hash_set(hash, key, sizeof(*key), y);
> >>   z = apr_hash_get(hash, key, sizeof(*key));
> >>
> >> rather than
> >>
> >>   abc_t *v = apr_pcalloc(pool, sizeof(abc_t));
> >>   apr_hash_set(hash, key, sizeof(key_t), y);
> >>   z = apr_hash_get(hash, key, sizeof(key_t));
> > We have had problems with both styles in the past, so neither is immune
> > to bugs.  I prefer the explicit type as it is easier to grep.
>
> The explicit type form is more accident-prone than the variable form
> because any change requires two modifications in the same statement
> instead of one.
>

Agreed. I much prefer the variable-based form. It works well for locals,
arguments, fields in a structure, dereferences, etc.

Cheers,
-g

Mime
View raw message