Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Oct 2004 17:37:17 +0200 (CEST)
From:      Harti Brandt <harti@freebsd.org>
To:        Dan Nelson <dnelson@allantgroup.com>
Cc:        Andreas Klemm <andreas@klemm.apsfilter.org>
Subject:   Re: please help with: warning: initialization makes integer from pointer
Message-ID:  <20041008173138.Y14215@beagle.kn.op.dlr.de>
In-Reply-To: <20041008152905.GA3106@dan.emsphone.com>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041008173138.Y14215>