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 K&R 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.


[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

Reply via email to