All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: Stefan Weil <weil@mail.berlios.de>
Cc: Blue Swirl <blauwirbel@gmail.com>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] Win32: Don't remove const attribute in type casts.
Date: Sat, 13 Jun 2009 17:30:32 +0100	[thread overview]
Message-ID: <20090613163032.GD16220@shareable.org> (raw)
In-Reply-To: <1244891127-15561-1-git-send-email-weil@mail.berlios.de>

Stefan Weil wrote:
> Type casts removing the const attribute are bad because
> they hide the fact that the argument remains const.
> 
> They also result in a compiler warning (at least with MS-C).

> -    return sendto(s->fd, (void *)buf, size, 0,
> +    return sendto(s->fd, (const void *)buf, size, 0,
>                    (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));

1. Why isn't the (struct sockaddr *) const too?

   It is declared like this in at least one Win32 header file:

      WINSOCK_API_LINKAGE int PASCAL sendto(SOCKET, const char*,
                                            int, int,
                                            const struct sockaddr*, int);

   So why does the buffer pointer need to be const, but the sockaddr
   does not, for MS-C to be happy?

2. Possibly just a historical note.  Passing a const pointer will
   produce compiler warnings or even errors on any platform where
   sendto is declared in system headers without const pointer
   arguments.  I think some old unixes did that, but probably QEMU
   isn't targetting any of them.

   However, it might be why the (void *) cast was put there in the
   first place, as there is no need for any cast at all on platforms
   where sendto() is declared the modern way.

3. See 2 - maybe just get rid of the cast?

-- Jamie

  parent reply	other threads:[~2009-06-13 16:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-13 11:05 [Qemu-devel] [PATCH] Win32: Don't remove const attribute in type casts Stefan Weil
2009-06-13 11:33 ` [Qemu-devel] " Blue Swirl
2009-06-13 16:30 ` Jamie Lokier [this message]
2009-06-13 18:58   ` [Qemu-devel] " Stefan Weil

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=20090613163032.GD16220@shareable.org \
    --to=jamie@shareable.org \
    --cc=blauwirbel@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=weil@mail.berlios.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.