git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [OT] Re: [PATCH] Use explicit pointers for execl...() sentinels.
Date: Mon, 13 Mar 2006 19:42:53 -0500	[thread overview]
Message-ID: <20060314004253.GA24668@coredump.intra.peff.net> (raw)
In-Reply-To: <200603130412.k2D4CW1b011631@laptop11.inf.utfsm.cl>

On Mon, Mar 13, 2006 at 12:12:31AM -0400, Horst von Brand wrote:

> Very improbable, they'll be the same normally ("void *" is a way of getting
> rid of the overloading of the meaning of "char *" for this before ANSI C).
> Sure, sizeof(int *) might be 4, but I think that is pretty far off.

Let me clarify my position. The STANDARD doesn't guarantee such things.
In PRACTICE, for modern machines you can assume that all pointers are
the same size (and things like all-bits-zero is a null pointer) if it
makes your code cleaner. In other words, I agree with Linus: git should
follow what works in practice, but you should at least recognize that
you're violating the standard.

That being said, you appear to be making the argument that passing a
'foo *' to a variadic function expecting a 'bar *' doesn't violate the
standard. I believe it invokes undefined behavior.

> There are special rules for variadic functions, probably pointers would be
> cast to/from void * in such a case by the compiler.

The rules indicate that arguments matching the '...' follow "default
argument promotion".  See section 6.5.2.2, paragraph 7.  This default
promotion is the same as what would happen if there were no prototype
for the function, and is defined in paragraph 6:
  ...the integer promotions are performed on each argument, and arguments
  that have type float are promoted to double.
I don't see anything about promoting pointers to void.

Furthermore, when accessing the arguments using va_arg, the types must
match or the behavior is undefined, UNLESS (7.5.1.1, para 2):
  - one type is signed and the other is the matching unsigned type
  - one type is a pointer to void and the other is a pointer of
    character type
IOW, the standard does promise that void* and char* pointers are
represented the same, but nothing else.

> > If you remain unconvinced, I can try to find chapter and verse of the
> > standard.
> Please do.

See above.

-Peff

  reply	other threads:[~2006-03-14  0:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-11 19:29 [PATCH] Trivial warning fix for imap-send.c Art Haas
2006-03-12 10:44 ` Mark Wooding
2006-03-12 11:27   ` Junio C Hamano
2006-03-12 13:59     ` [PATCH] Use explicit pointers for execl...() sentinels Mark Wooding
2006-03-12 15:13       ` Timo Hirvonen
2006-03-12 17:32         ` Mark Wooding
2006-03-12 18:08           ` Timo Hirvonen
2006-03-13  3:31             ` Jeff King
2006-03-13  4:12               ` Horst von Brand
2006-03-14  0:42                 ` Jeff King [this message]
2006-03-12 16:57   ` [PATCH] Trivial warning fix for imap-send.c Linus Torvalds
2006-03-12 18:01     ` Mark Wooding
2006-03-12 19:20       ` A Large Angry SCM
2006-03-13  2:59         ` H. Peter Anvin
2006-03-13  4:36           ` A Large Angry SCM
2006-03-13  5:22             ` Linus Torvalds
2006-03-13  6:37               ` H. Peter Anvin
2006-03-13  6:46                 ` Linus Torvalds
2006-03-13 16:37                 ` Olivier Galibert
2006-03-13  3:38         ` Jeff King
2006-03-13  4:14           ` Horst von Brand
2006-03-13 16:26             ` Linus Torvalds
2006-03-13  6:41           ` H. Peter Anvin
2006-03-12 21:51       ` Horst von Brand
2006-03-12 23:02       ` Linus Torvalds

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=20060314004253.GA24668@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /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).