From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MFW7s-00034b-Ok for qemu-devel@nongnu.org; Sat, 13 Jun 2009 12:30:40 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MFW7o-000341-ED for qemu-devel@nongnu.org; Sat, 13 Jun 2009 12:30:40 -0400 Received: from [199.232.76.173] (port=54217 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MFW7o-00033y-Bm for qemu-devel@nongnu.org; Sat, 13 Jun 2009 12:30:36 -0400 Received: from mail2.shareable.org ([80.68.89.115]:37850) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MFW7n-000066-Uf for qemu-devel@nongnu.org; Sat, 13 Jun 2009 12:30:36 -0400 Date: Sat, 13 Jun 2009 17:30:32 +0100 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] Win32: Don't remove const attribute in type casts. Message-ID: <20090613163032.GD16220@shareable.org> References: <1244891127-15561-1-git-send-email-weil@mail.berlios.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1244891127-15561-1-git-send-email-weil@mail.berlios.de> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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