Re: NULL pointer and zero value
On Tue, 30 Dec 2003 14:07:21 GMT, pete <pfiland@mindsp ring.com> wrote
in comp.lang.c:
[color=blue]
> Martin Dickopp wrote:[color=green]
> >
> > dt1649651@yahoo .com (vp) writes:
> >[color=darkred]
> > > If I have a pointer char * p, is it correct to assign NULL to this
> > > pointer by:
> > >
> > > "memset( &p, 0, sizeof(p));" instead of "p = NULL;"[/color]
> >
> > No. The former statement sets all bits of `p' to zero, which is not
> > necessarily a representation of the null pointer.
> >[color=darkred]
> > > The reason I ask is I have an array of structure of N function
> > > variables, for example,
> > >
> > > typedef struct
> > > {
> > > int (* func1)();
> > > int (* func2)();
> > > void * (* func2)(int );
> > > } ModuleFunctions ;
> > >
> > > #define N 100
> > > ModuleFunction garMF[N];
> > >
> > > When initializing, instead of making a loop to assgin NULL to each
> > > function member of struct ModuleFunction
> > > for each member of array, is it correct to do something like
> > >
> > > memset( garMF, 0, sizeof(ModuleFu nctions)*N );[/color][/color]
>[color=green]
> > Otherwise (if `garMF' doesn't have static storage duration)
> > you'll have to loop.[/color]
>
> I disagree about the necessity of a loop.
>
> ModuleFunction garMF[N] = {NULL};[/color]
I would much prefer {0} to {NULL} here.
--
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.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
On Tue, 30 Dec 2003 14:07:21 GMT, pete <pfiland@mindsp ring.com> wrote
in comp.lang.c:
[color=blue]
> Martin Dickopp wrote:[color=green]
> >
> > dt1649651@yahoo .com (vp) writes:
> >[color=darkred]
> > > If I have a pointer char * p, is it correct to assign NULL to this
> > > pointer by:
> > >
> > > "memset( &p, 0, sizeof(p));" instead of "p = NULL;"[/color]
> >
> > No. The former statement sets all bits of `p' to zero, which is not
> > necessarily a representation of the null pointer.
> >[color=darkred]
> > > The reason I ask is I have an array of structure of N function
> > > variables, for example,
> > >
> > > typedef struct
> > > {
> > > int (* func1)();
> > > int (* func2)();
> > > void * (* func2)(int );
> > > } ModuleFunctions ;
> > >
> > > #define N 100
> > > ModuleFunction garMF[N];
> > >
> > > When initializing, instead of making a loop to assgin NULL to each
> > > function member of struct ModuleFunction
> > > for each member of array, is it correct to do something like
> > >
> > > memset( garMF, 0, sizeof(ModuleFu nctions)*N );[/color][/color]
>[color=green]
> > Otherwise (if `garMF' doesn't have static storage duration)
> > you'll have to loop.[/color]
>
> I disagree about the necessity of a loop.
>
> ModuleFunction garMF[N] = {NULL};[/color]
I would much prefer {0} to {NULL} here.
--
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.l earn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Comment