Re: NULL pointer and zero value

From: Jack Klein (jackklein_at_spamcop.net)
Date: 12/31/03


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


Relevant Pages

  • Re: NULL pointer and zero value
    ... static or automatic scalar or aggregate type. ... simplicity's sake, they are "0" and "(void *)0", or equivalent. ... cast to rather than the raw numeric constant. ...
    (comp.lang.c)
  • Re: Microsoft style:
    ... members of the class or struct, ... void THING::SetDate ... common words like the verb 'to be' are short and irregular but less used ...
    (microsoft.public.vc.mfc)
  • Re: Managed method in Native Class ?
    ... > void myClass::myMethod ... the members occupy a slot in the objects vtable laid-out by the compiler. ... a managed method cannot be a member of a native class. ...
    (microsoft.public.dotnet.languages.vc)
  • Ported to 2005 - Strange variable alignment causing issues
    ... I'm migrating an old Visual C++ 6 project ... Just one class is misbehaving - it's member variables are ... members are NOT aligned and it's not so well. ... void UpdateOutText; ...
    (microsoft.public.vc.language)
  • Re: Is continuum completely filled up?
    ... Therfore real line has void. ... But a line is made up from points and intervalls between points - ... but this one is called standard topology. ... In latter case,we can discribe its members by stating that counting member ...
    (sci.math)