Re: [PATCH 00/15] Rearrange xcalloc arguments

2014-05-27 Thread Jeff King
On Mon, May 26, 2014 at 04:37:41PM -0700, Jeremiah Mahler wrote:

  xcalloc takes two arguments: the number of elements and their size.
  The vast majority of the Git codebase passes these arguments in the
  correct order, but there are some exceptions. This patch series
  corrects those exceptions.
  
 
 Let me see if I understand the issue underlying this patch set.
 
 xcalloc works like calloc and takes two arguments, the number of
 elements and the size of each element.  However, many calls specified
 these arguments in the reverse order.  It didn't produce a compile
 error because both arguments are the same type.  And it didn't produce
 a run time error because A*B is the same as B*A.

Yes, I think that is a good summary.

It may be theoretically possible that an implementation of calloc()
can use the distinction between the two arguments to adjust the padding
or alignment of the result. However, I don't know if any implementation
actually does this, or if it is even true in theory. You can find
some discussions[1,2] online, but nothing conclusive. The most plausible
theory I saw is that early KR C may have done something clever here,
but ANSI C alignment requirements effectively remove any wiggle room for
the implementation.

But it certainly does not hurt to follow the spec and be consistent.

-Peff

[1] http://stackoverflow.com/questions/501839/is-calloc4-6-the-same-as-calloc6-4

[2] https://groups.google.com/d/msg/comp.lang.c/jZbiyuYqjB4/NIAmeNd11IoJ
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/15] Rearrange xcalloc arguments

2014-05-26 Thread Jeremiah Mahler
Brian,

On Tue, May 27, 2014 at 12:33:41AM +0900, Brian Gesiak wrote:
 xcalloc takes two arguments: the number of elements and their size.
 The vast majority of the Git codebase passes these arguments in the
 correct order, but there are some exceptions. This patch series
 corrects those exceptions.
 

Let me see if I understand the issue underlying this patch set.

xcalloc works like calloc and takes two arguments, the number of
elements and the size of each element.  However, many calls specified
these arguments in the reverse order.  It didn't produce a compile
error because both arguments are the same type.  And it didn't produce
a run time error because A*B is the same as B*A.

If this behaved like dd, performance would be different depending on the
order.

  dd if=in of=out bs=1count=1024
  dd if=in of=out bs=1024 count=1

Nonetheless, it appears to be a good fix.  Nice job!

-- 
Jeremiah Mahler
jmmah...@gmail.com
http://github.com/jmahler
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html