git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Jeremiah Mahler <jmmahler@gmail.com>,
	Brian Gesiak <modocache@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH 00/15] Rearrange xcalloc arguments
Date: Tue, 27 May 2014 21:16:58 -0400	[thread overview]
Message-ID: <20140528011658.GA17688@sigill.intra.peff.net> (raw)
In-Reply-To: <20140526233741.GB8570@hudson.localdomain>

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.

-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

      reply	other threads:[~2014-05-28  1:17 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-26 15:33 [PATCH 00/15] Rearrange xcalloc arguments Brian Gesiak
2014-05-26 15:33 ` [PATCH 01/15] builtin/add.c: rearrange " Brian Gesiak
2014-05-26 23:11   ` Jeremiah Mahler
2014-05-27  2:22     ` Brian Gesiak
2014-05-27  2:38       ` Jeremiah Mahler
2014-05-27  3:25   ` Eric Sunshine
2014-05-27 11:32     ` Brian Gesiak
2014-05-27 21:35       ` Eric Sunshine
2014-05-27 22:41         ` Junio C Hamano
2014-05-28  5:14         ` Jeremiah Mahler
2014-05-28  5:56           ` Brian Gesiak
2014-05-26 15:33 ` [PATCH 02/15] builtin/ls-remote.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 03/15] builtin/remote.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 04/15] commit.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 05/15] config.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 06/15] diff.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 07/15] hash.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 08/15] hash.h: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 09/15] http-push.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 10/15] imap-send.c: " Brian Gesiak
2014-06-10 21:54   ` Jeremiah Mahler
2014-05-26 15:33 ` [PATCH 11/15] notes.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 12/15] pack-revindex.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 13/15] reflog-walk.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 14/15] remote.c: " Brian Gesiak
2014-05-26 15:33 ` [PATCH 15/15] transport-helper.c: " Brian Gesiak
2014-05-26 23:37 ` [PATCH 00/15] Rearrange " Jeremiah Mahler
2014-05-28  1:16   ` Jeff King [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140528011658.GA17688@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=jmmahler@gmail.com \
    --cc=modocache@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).