* [Qemu-devel] [PATCH] Win32: Don't remove const attribute in type casts.
@ 2009-06-13 11:05 Stefan Weil
2009-06-13 11:33 ` [Qemu-devel] " Blue Swirl
2009-06-13 16:30 ` [Qemu-devel] " Jamie Lokier
0 siblings, 2 replies; 4+ messages in thread
From: Stefan Weil @ 2009-06-13 11:05 UTC (permalink / raw)
To: QEMU Developers, Blue Swirl
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).
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
net.c | 2 +-
qemu-char.c | 2 +-
vnc.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/net.c b/net.c
index 58d68b5..af9de73 100644
--- a/net.c
+++ b/net.c
@@ -1507,7 +1507,7 @@ static ssize_t net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf,
{
NetSocketState *s = vc->opaque;
- 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));
}
diff --git a/qemu-char.c b/qemu-char.c
index a63d860..a8afe94 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1708,7 +1708,7 @@ static int udp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
{
NetCharDriver *s = chr->opaque;
- return sendto(s->fd, (void *)buf, len, 0,
+ return sendto(s->fd, (const void *)buf, len, 0,
(struct sockaddr *)&s->daddr, sizeof(struct sockaddr_in));
}
diff --git a/vnc.c b/vnc.c
index 109c2f3..e1ca9f8 100644
--- a/vnc.c
+++ b/vnc.c
@@ -961,7 +961,7 @@ long vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen)
}
} else
#endif /* CONFIG_VNC_TLS */
- ret = send(vs->csock, (void *)data, datalen, 0);
+ ret = send(vs->csock, (const void *)data, datalen, 0);
VNC_DEBUG("Wrote wire %p %zd -> %ld\n", data, datalen, ret);
return vnc_client_io_error(vs, ret, socket_error());
}
--
1.5.6.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] Re: [PATCH] Win32: Don't remove const attribute in type casts.
2009-06-13 11:05 [Qemu-devel] [PATCH] Win32: Don't remove const attribute in type casts Stefan Weil
@ 2009-06-13 11:33 ` Blue Swirl
2009-06-13 16:30 ` [Qemu-devel] " Jamie Lokier
1 sibling, 0 replies; 4+ messages in thread
From: Blue Swirl @ 2009-06-13 11:33 UTC (permalink / raw)
To: Stefan Weil; +Cc: QEMU Developers
On 6/13/09, Stefan Weil <weil@mail.berlios.de> 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).
>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
Thanks, applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] Win32: Don't remove const attribute in type casts.
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
2009-06-13 18:58 ` Stefan Weil
1 sibling, 1 reply; 4+ messages in thread
From: Jamie Lokier @ 2009-06-13 16:30 UTC (permalink / raw)
To: Stefan Weil; +Cc: Blue Swirl, QEMU Developers
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] Win32: Don't remove const attribute in type casts.
2009-06-13 16:30 ` [Qemu-devel] " Jamie Lokier
@ 2009-06-13 18:58 ` Stefan Weil
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Weil @ 2009-06-13 18:58 UTC (permalink / raw)
To: Jamie Lokier; +Cc: QEMU Developers
Jamie Lokier schrieb:
> 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.
Correct.
>
> 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
>
const was not added to the type cast because the
function prototype allows a const pointer argument.
const was added because the casted value (buf) has this attribute.
&s->dgram_dst is part of s which does not have a const attribute,
so there is no need to add const to that type cast.
Replacing uint8_t * by void * in many QEMU's functions
might be the best solution to get rid of type casts,
but that can only be done by a maintainer (or at least
the maintainers must support such changes).
Regards,
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-06-13 18:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [Qemu-devel] " Jamie Lokier
2009-06-13 18:58 ` Stefan Weil
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.