From owner-cvs-src@FreeBSD.ORG Tue Dec 4 19:14:32 2007 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CA47C16A418; Tue, 4 Dec 2007 19:14:32 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) Received: from pobox.codelabs.ru (pobox.codelabs.ru [144.206.177.45]) by mx1.freebsd.org (Postfix) with ESMTP id 7107213C442; Tue, 4 Dec 2007 19:14:32 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) DomainKey-Signature: a=rsa-sha1; q=dns; c=simple; s=one; d=codelabs.ru; h=Received:Date:From:To:Cc:Message-ID:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:Sender:X-Spam-Status:Subject; b=fxttMj+2giO6NbBmqn6eMZSjnuVZBFwo4+yvutACXyOokHbNYRDymY7YxwVR36ZZkCA8O54fHEUCXLRcxqx3Q7Gt8ZZ7NiBuSTsTA/W7RzNpNdi/+ANvQmpISFgGWePCPwslPUyWjIH/cxy+pW6pzFjCPvQdiPmi5HFop34sTvQ=; Received: from void.codelabs.ru (void.codelabs.ru [144.206.177.25]) by pobox.codelabs.ru with esmtpsa (TLSv1:AES256-SHA:256) id 1Izcui-0003wZ-JK; Tue, 04 Dec 2007 21:54:36 +0300 Date: Tue, 4 Dec 2007 21:54:34 +0300 From: Eygene Ryabinkin To: Alexey Dokuchaev Message-ID: References: <200711232356.lANNu3mp040885@repoman.freebsd.org> <864pezer7f.fsf@ds4.des.no> <200712031657.34074.jhb@freebsd.org> <20071204172535.GB82261@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <20071204172535.GB82261@FreeBSD.org> Sender: rea-fbsd@codelabs.ru X-Spam-Status: No, score=-2.0 required=4.0 tests=ALL_TRUSTED,AWL,BAYES_40 Cc: src-committers@freebsd.org, John Baldwin , cvs-src@freebsd.org, cvs-all@freebsd.org, John Birrell , Dag-Erling Sm??rgrav Subject: Re: cvs commit: src/sys/netinet/libalias alias_util.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Dec 2007 19:14:32 -0000 Tue, Dec 04, 2007 at 05:25:35PM +0000, Alexey Dokuchaev wrote: > > *ptr++ would choke since pointer arith on (void *) is undefined AFAIK. > > I've been under impression that ++ on void * whould simply increase it > by one. This behaviour is documented for GCC: http://www.mcs.vuw.ac.nz/cgi-bin/info2www?(gcc)Pointer+Arith Just for the record (gcc 4.2.1): ----- $ gcc -o test -Wall -ansi -pedantic test.c test.c: In function 'main': test.c:9: warning: wrong type argument to increment $ ./test '2' $ g++ -o test -Wall -ansi test.c test.c: In function 'int main()': test.c:9: error: ISO C++ forbids incrementing a pointer of type 'void*' $ cat test.c #include int main(void) { char c[] = "123456789abcdef"; void *p = c; p++; printf("'%c'\n", *((char *)p)); return 0; } ----- It seems to me that ++ adds one to the void pointer because it is demanded by C99 (ISO/IEC 9899:TC2, 6.2.5, requirement 26, page 36) that 'char *' and 'void *' have the same representation and alignment requirements. So, it seems to me that (p++) has implicit conversion from 'void *' to 'char *' for 'void *p', at least it can be interpreted in this way. But some people say that void* arithmetics is GCC'ism. It worth to note that the warning about void* arithmetics lived in GCC at least since 1992: see http://gcc.gnu.org/viewcvs/trunk/gcc/c-typeck.c?revision=364&view=markup function 'pointer_int_sum'. And the problem of 'void *' arithmetics had been touched in the -current a while ago: http://lists.freebsd.org/pipermail/freebsd-current/2003-July/006439.html I am failing to find a place in the C standard where void arithmetics is prohibited, but I can be blind. Anyone? -- Eygene