From owner-freebsd-current@FreeBSD.ORG Thu Jul 10 02:24:11 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5D3C837B401 for ; Thu, 10 Jul 2003 02:24:11 -0700 (PDT) Received: from mailhub.fokus.fraunhofer.de (mailhub.fokus.fraunhofer.de [193.174.154.14]) by mx1.FreeBSD.org (Postfix) with ESMTP id 26DC643FAF for ; Thu, 10 Jul 2003 02:24:08 -0700 (PDT) (envelope-from brandt@fokus.fraunhofer.de) Received: from beagle (beagle [193.175.132.100])h6A9O2Q27345; Thu, 10 Jul 2003 11:24:02 +0200 (MEST) Date: Thu, 10 Jul 2003 11:24:02 +0200 (CEST) From: Harti Brandt To: Luigi Rizzo In-Reply-To: <20030710011956.A61125@xorpc.icir.org> Message-ID: <20030710111332.C30571@beagle.fokus.fraunhofer.de> References: <20030710011956.A61125@xorpc.icir.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: current@freebsd.org Subject: Re: what is the suggested way to do void * arithmetic ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jul 2003 09:24:11 -0000 On Thu, 10 Jul 2003, Luigi Rizzo wrote: LR> LR>Hi, LR>in several places in ipfw2.c i have to move pointers across LR>structures of variable length (lists of ipfw2 instructions LR>returned by the getsockopt()), and i use the following type of code: LR> LR> void *next; LR> foo *p; LR> LR> ... LR> LR> next = (void *)p + len; LR> ... LR> foo = (foo *)p + len; LR> LR>When using WARNS=5, the compiler in -current flags them with 'Warning LR>void * arithmetic'. LR> LR>What is the best way to do the above given that i do need to use LR>these variable-size structures ? Because sizeof(char), sizeof(unsigned char) and sizeof(signed char) all are defined to be 1 by the standard, any of them'll do it. Arithmetic on void pointers is undefined by the standard. next_foo = (struct foo *)((char *)this_foo + this_foo->len); provided that the object pointed to by this_foo is at least this_foo->len bytes long. harti -- harti brandt, http://www.fokus.fraunhofer.de/research/cc/cats/employees/hartmut.brandt/private brandt@fokus.fraunhofer.de, harti@freebsd.org