Re: NULL pointer and zero value
From: Jack Klein (jackklein_at_spamcop.net)
Date: 12/31/03
- Next message: Jack Klein: "Re: NULL pointer and zero value"
- Previous message: Jack Klein: "Re: Does this cause undefined behaviour?"
- In reply to: pete: "Re: NULL pointer and zero value"
- Next in thread: CBFalconer: "Re: NULL pointer and zero value"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Dec 2003 16:24:40 GMT
On Wed, 31 Dec 2003 12:46:37 GMT, pete <pfiland@mindspring.com> wrote
in comp.lang.c:
> Jack Klein wrote:
> >
> > On Tue, 30 Dec 2003 14:07:21 GMT,
> > pete <pfiland@mindspring.com wrote in comp.lang.c:
>
> > > > > typedef struct
> > > > > {
> > > > > int (* func1)();
> > > > > int (* func2)();
> > > > > void * (* func2)(int );
> > > > > } ModuleFunctions;
> > > > >
> > > > > #define N 100
> > > > > ModuleFunction garMF[N];
>
> > > ModuleFunction garMF[N] = {NULL};
> >
> > I would much prefer {0} to {NULL} here.
>
> All of the members of all of the elements of the array
> will be initialized to NULL. Why do you like {0} better ?
I should have elaborated. {0} works in all cases to initialize any
static or automatic scalar or aggregate type.
The C standard allows two definitions for the macro NULL. For
simplicity's sake, they are "0" and "(void *)0", or equivalent. My
experience is that most (but definitely not all) C compilers use the
cast to (void *) rather than the raw numeric constant.
In this case, since the first element of the structure has pointer
type, either definition of NULL will work. If the structure had a
non-pointer first member, it would be correct on implementations that
used a raw 0 for NULL, but be a constraint violation on those that
defined NULL as "(void *)0".
-- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
- Next message: Jack Klein: "Re: NULL pointer and zero value"
- Previous message: Jack Klein: "Re: Does this cause undefined behaviour?"
- In reply to: pete: "Re: NULL pointer and zero value"
- Next in thread: CBFalconer: "Re: NULL pointer and zero value"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|