From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 41263 invoked by alias); 2 Nov 2015 21:06:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 41251 invoked by uid 89); 2 Nov 2015 21:06:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 02 Nov 2015 21:06:00 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id D19298CF6E; Mon, 2 Nov 2015 21:05:58 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tA2L5vkA005483; Mon, 2 Nov 2015 16:05:58 -0500 Message-ID: <5637D035.8090801@redhat.com> Date: Mon, 02 Nov 2015 21:06:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PATCH 06/11] [C++/mingw] ser-tcp.c casts References: <1446492970-21432-1-git-send-email-palves@redhat.com> <1446492970-21432-7-git-send-email-palves@redhat.com> <5637CA30.4080200@ericsson.com> <5637CDBE.40703@redhat.com> In-Reply-To: <5637CDBE.40703@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-11/txt/msg00054.txt.bz2 On 11/02/2015 08:55 PM, Pedro Alves wrote: > On 11/02/2015 08:40 PM, Simon Marchi wrote: >> You could have done exactly the opposite of the old comment, that is cast to >> (char *). It shouldn't generate any warning in either case. But I think that >> your way is fine too. > > Oh, good point. I always forget that implicit cast to void* works. > > I'll update the patch. Here it is. Build tested on GNU/Linux and mingw. --- >From 574dbd59c93e29f494bad7688cb04b1672d3980a Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 2 Nov 2015 20:56:15 +0000 Subject: [PATCH] [C++/mingw] ser-tcp.c casts Fixes a few errors like these: ../../src/gdb/ser-tcp.c: In function 'int net_open(serial*, const char*)': ../../src/gdb/ser-tcp.c:286:73: error: invalid conversion from 'void*' to 'char*' [-fpermissive] res = getsockopt (scb->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len); ^ gdb/ChangeLog: 2015-11-01 Pedro Alves * ser-tcp.c (net_open) : Cast getsockopt argument to char * instead of void *. Update comment. (net_read_prim): Cast recv argument to char * instead of void *. (net_write_prim): Cast send argument to char *. Add comment. --- gdb/ser-tcp.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c index ce40b61..36196f3 100644 --- a/gdb/ser-tcp.c +++ b/gdb/ser-tcp.c @@ -280,10 +280,10 @@ net_open (struct serial *scb, const char *name) len = sizeof (err); /* On Windows, the fourth parameter to getsockopt is a "char *"; - on UNIX systems it is generally "void *". The cast to "void *" - is OK everywhere, since in C "void *" can be implicitly - converted to any pointer type. */ - res = getsockopt (scb->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len); + on UNIX systems it is generally "void *". The cast to "char *" + is OK everywhere, since in C++ any data pointer type can be + implicitly converted to "void *". */ + res = getsockopt (scb->fd, SOL_SOCKET, SO_ERROR, (char *) &err, &len); if (res < 0 || err) { /* Maybe the target still isn't ready to accept the connection. */ @@ -342,13 +342,17 @@ net_read_prim (struct serial *scb, size_t count) /* Need to cast to silence -Wpointer-sign on MinGW, as Winsock's 'recv' takes 'char *' as second argument, while 'scb->buf' is 'unsigned char *'. */ - return recv (scb->fd, (void *) scb->buf, count, 0); + return recv (scb->fd, (char *) scb->buf, count, 0); } int net_write_prim (struct serial *scb, const void *buf, size_t count) { - return send (scb->fd, buf, count, 0); + /* On Windows, the second parameter to send is a "const char *"; on + UNIX systems it is generally "const void *". The cast to "const + char *" is OK everywhere, since in C++ any data pointer type can + be implicitly converted to "const void *". */ + return send (scb->fd, (const char *) buf, count, 0); } int -- 1.9.3