From owner-freebsd-hackers@FreeBSD.ORG Fri Oct 8 15:37:31 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3589E16A4E7 for ; Fri, 8 Oct 2004 15:37:31 +0000 (GMT) Received: from n33.kp.t-systems-sfr.com (n33.kp.t-systems-sfr.com [129.247.16.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3FF3E43D31 for ; Fri, 8 Oct 2004 15:37:30 +0000 (GMT) (envelope-from harti@freebsd.org) Received: from n81.sp.op.dlr.de (n81g.sp.op.dlr.de [129.247.163.1]) i98FbIU565292; Fri, 8 Oct 2004 17:37:18 +0200 Received: from zeus.nt.op.dlr.de (zeus.nt.op.dlr.de [129.247.173.3]) i98FbHI82820; Fri, 8 Oct 2004 17:37:17 +0200 Received: from beagle.kn.op.dlr.de (opkndnwsbsd178 [129.247.173.178]) by zeus.nt.op.dlr.de (8.11.7+Sun/8.9.1) with ESMTP id i98FbGe21314; Fri, 8 Oct 2004 17:37:17 +0200 (MET DST) Date: Fri, 8 Oct 2004 17:37:17 +0200 (CEST) From: Harti Brandt X-X-Sender: brandt@beagle.kn.op.dlr.de To: Dan Nelson In-Reply-To: <20041008152905.GA3106@dan.emsphone.com> Message-ID: <20041008173138.Y14215@beagle.kn.op.dlr.de> References: <20041005054213.GA11770@lesanti.hq.sinectis.com.ar> <20041005202816.GA14973@titan.klemm.apsfilter.org> <20041005205040.GH31397@lesanti.hq.sinectis.com.ar> <20041006060437.GA23364@titan.klemm.apsfilter.org> <20041006144220.GA29653@lesanti.hq.sinectis.com.ar> <416579E1.8050308@nuclearelephant.com> <20041008152905.GA3106@dan.emsphone.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: hackers@freebsd.org cc: Andreas Klemm Subject: Re: please help with: warning: initialization makes integer from pointer X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Harti Brandt List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Oct 2004 15:37:31 -0000 On Fri, 8 Oct 2004, Dan Nelson wrote: DN>In the last episode (Oct 07), Andreas Klemm said: DN>> Dear FreeBSD hackers, DN>> DN>> could somebody please help Jonathan, the dspam owner, how to code DN>> this best under FreeBSD ? DN>> DN>> Please see his question below: DN>> DN>> On Thu, Oct 07, 2004 at 01:16:17PM -0400, Jonathan A. Zdziarski wrote: DN>> > I'm a little concerned about these warnings: DN>> > DN>> > pgsql_drv.c:873: warning: initialization makes integer from pointer without a cast DN>> > pgsql_drv.c:874: warning: initialization makes integer from pointer without a cast DN>> > DN>> > This could cause some problems with dspam. Is there a freeBSDish way to DN>> > do this: DN>> > DN>> > s->p_getpwnam = (struct passwd) { NULL, NULL, 0, 0, NULL, NULL, NULL }; DN>> > s->p_getpwuid = (struct passwd) { NULL, NULL, 0, 0, NULL, NULL, NULL }; DN>> > DN>> > Perhaps memset(s->p_getpwnam, 0, sizeof(struct passwd)) ? DN> DN>Yes, memset would be much more portable. I don't think there is any DN>standard that says how many fields struct passwd has, or if they must DN>be in any order. POSIX names only 5 required fields and no order. DN> DN>You could use designated initialization, but that's a C99 feature, and DN>since you're initializing everything to zero anyway, memset is still DN>better. Memset is actually not portable if the structure contains pointers because it would initialize the pointers to 0 values not to 0 pointers. A 0 pointer not necessarily has a 0 value. A pointer can be portably be initialize to the 0-pointer only by assigning NULL (or 0) (or by assigning another pointer that is alreay initialized). If you don't want to use designated initialisation and need portability, you must either explicitely assign all the members that are definied in the standard or use: static const struct passwd passwd_0; ... s->p_getpwnam = passwd_0; ... harti