On Tue, Aug 11, 2015 at 4:02 PM, Philip Martin <philip.mar...@wandisco.com> wrote:
> Stefan Fuhrmann <stefan.fuhrm...@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. Absolutely, neither way is foolproof. The variable-based variant is prone to using the wrong level of indirection, for instance. Once the code has been debugged, though, the variable- based variant should have better maintainability because it is closer to the single point of definition principle. And I found that usage easier to verify during my review. > I prefer the explicit type as it is easier to grep. > What do you grep for, specifically? The type should already show up for the variable / function argument declaration - so, you should not miss a type usage either way. -- Stefan^2.