By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

NULL pointer and zero value

P: n/a
vp
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;"

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(ModuleFunctions)*N );
Thanks for your help,

DT
Nov 14 '05 #1
Share this Question
Share on Google+
31 Replies


P: n/a
vp wrote:
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;"


No. NULL is not necessarily all-bits-zero.

Your technique will, however, work by chance on quite a few platforms,
because quite a few platforms do use all-bits-zero for NULL. If you like
programming-by-casino, go ahead. :-)

<snip>

--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #2

P: n/a
Richard Heathfield <in*****@address.co.uk.invalid> spoke thus:
(all-bits 0 as NULL post)

If you like programming-by-casino, go ahead. :-)


So the house wins on NULL and double NULL? ;)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #3

P: n/a
dt*******@yahoo.com (vp) writes:
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;"
No. The former statement sets all bits of `p' to zero, which is not
necessarily a representation of the null pointer.
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(ModuleFunctions)*N );


If `garMF' has static storage duration, it is automatically initialized to
zero if you don't initialize it explicitly. "Initialized to zero" means
that each non-compound object is initialized as if you assigned `0' to it
(i.e. pointers are initialized to null pointers). For compound objects,
its members or elements are recursively initialized in this way.

Otherwise (if `garMF' doesn't have static storage duration) you'll have
to loop.

Martin
Nov 14 '05 #4

P: n/a
Richard Heathfield <in*****@address.co.uk.invalid> wrote in
news:3f******@news2.power.net.uk:
No. NULL is not necessarily all-bits-zero.

Your technique will, however, work by chance on quite a few platforms,
because quite a few platforms do use all-bits-zero for NULL. If you like
programming-by-casino, go ahead. :-)


So are you saying that this isn't safe?

#include <stdlib.h>

int main(void)
{
int *pVar = malloc(1024);

if (pVar) /* <--- Not safe? */
{
free(pVar);
}

return EXIT_SUCCESS;
}

--
- Mark ->
--
Nov 14 '05 #5

P: n/a
Martin Dickopp wrote:

dt*******@yahoo.com (vp) writes:
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;"
No. The former statement sets all bits of `p' to zero, which is not
necessarily a representation of the null pointer.
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(ModuleFunctions)*N );

Otherwise (if `garMF' doesn't have static storage duration)
you'll have to loop.


I disagree about the necessity of a loop.

ModuleFunction garMF[N] = {NULL};

--
pete
Nov 14 '05 #6

P: n/a
Mark A. Odell wrote:

Richard Heathfield <in*****@address.co.uk.invalid> wrote in
news:3f******@news2.power.net.uk:
No. NULL is not necessarily all-bits-zero.

Your technique will, however,
work by chance on quite a few platforms,
because quite a few platforms do use all-bits-zero for NULL.
If you like programming-by-casino, go ahead. :-)


So are you saying that this isn't safe?

#include <stdlib.h>

int main(void)
{
int *pVar = malloc(1024);

if (pVar) /* <--- Not safe? */


Your code does not check to see if all bits are zero.

Your question and corresponding code example
are not relevant to what Richard Heathfield said.

--
pete
Nov 14 '05 #7

P: n/a
"Mark A. Odell" <no****@embeddedfw.com> writes:
Richard Heathfield <in*****@address.co.uk.invalid> wrote in
news:3f******@news2.power.net.uk:
No. NULL is not necessarily all-bits-zero.

Your technique will, however, work by chance on quite a few platforms,
because quite a few platforms do use all-bits-zero for NULL. If you like
programming-by-casino, go ahead. :-)


So are you saying that this isn't safe?

#include <stdlib.h>

int main(void)
{
int *pVar = malloc(1024);

if (pVar) /* <--- Not safe? */
{
free(pVar);
}

return EXIT_SUCCESS;
}


The program is correct (i.e. strictly conforming). The `if' statement
doesn't look at the representation (i.e. the bits) of `pVar', it simply
compares `pVar' to `0'. A comparison between an expression of pointer
type and `0', which is a null pointer constant in such a comparison, is
valid.

Martin
Nov 14 '05 #8

P: n/a
pete wrote:

Mark A. Odell wrote:

Richard Heathfield <in*****@address.co.uk.invalid> wrote in
news:3f******@news2.power.net.uk:
No. NULL is not necessarily all-bits-zero.

Your technique will, however,
work by chance on quite a few platforms,
because quite a few platforms do use all-bits-zero for NULL.
If you like programming-by-casino, go ahead. :-)


So are you saying that this isn't safe?

#include <stdlib.h>

int main(void)
{
int *pVar = malloc(1024);

if (pVar) /* <--- Not safe? */


Your code does not check to see if all bits are zero.

Your question and corresponding code example
are not relevant to what Richard Heathfield said.


The question is relevant, the answer is "no".

--
pete
Nov 14 '05 #9

P: n/a
vp wrote:

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;"


NO.

While it will often "work" on a particular system, it is not
portable and can lead to very mysterious bugs.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

Nov 14 '05 #10

P: n/a
Martin Dickopp <ex****************@zero-based.org> wrote in
news:bs*************@news.t-online.com:
So are you saying that this isn't safe?

#include <stdlib.h>

int main(void)
{
int *pVar = malloc(1024);

if (pVar) /* <--- Not safe? */
{
free(pVar);
}

return EXIT_SUCCESS;
}


The program is correct (i.e. strictly conforming). The `if' statement
doesn't look at the representation (i.e. the bits) of `pVar', it simply
compares `pVar' to `0'. A comparison between an expression of pointer
type and `0', which is a null pointer constant in such a comparison, is
valid.


Excellent. Thank you.

--
- Mark ->
--
Nov 14 '05 #11

P: n/a
vp
dt*******@yahoo.com (vp) wrote in message news:<24**************************@posting.google. com>...
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;"

[...]

Thanks for all of your replies and explanation. I see that I just can
not be lazy to make that memset. I don't want to put Las Vegas into my
app :-)

DT
Nov 14 '05 #12

P: n/a
vp
"Mark A. Odell" <no****@embeddedfw.com> wrote in message news:<Xn********************************@130.133.1 .4>...
Richard Heathfield <in*****@address.co.uk.invalid> wrote in
news:3f******@news2.power.net.uk:
No. NULL is not necessarily all-bits-zero.

Your technique will, however, work by chance on quite a few platforms,
because quite a few platforms do use all-bits-zero for NULL. If you like
programming-by-casino, go ahead. :-)


So are you saying that this isn't safe?

#include <stdlib.h>

int main(void)
{
int *pVar = malloc(1024);

if (pVar) /* <--- Not safe? */
{
free(pVar);
}

return EXIT_SUCCESS;
}


I guess the compiler will do the necessary comparison in this case. I
often see this style of code "if ( pointer )", but personally I often
write it like "if ( p != NULL )" just to remind me or my co-workers
that p is of pointer-type.

DT
Nov 14 '05 #13

P: n/a
dt*******@yahoo.com (vp) wrote in
news:24**************************@posting.google.c om:
if (pVar) /* <--- Not safe? */
{
free(pVar);
}

return EXIT_SUCCESS;
}


I guess the compiler will do the necessary comparison in this case. I
often see this style of code "if ( pointer )", but personally I often
write it like "if ( p != NULL )" just to remind me or my co-workers
that p is of pointer-type.


I avoid explicit checks for boolean conditions and since all my pointer
vars have a lower-case p in front, e.g. pSomeName, this is never an issue
for me. Besides, if I want to know if 'foo' is a pointer then I just hover
over it with my mouse and CodeWright shows me the definition. I thought
all editors could do such simple things. ;-)

--
- Mark ->
--
Nov 14 '05 #14

P: n/a
dt*******@yahoo.com (vp) writes:
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;"


No.

The C FAQ is at <http://www.eskimo.com/~scs/C-faq/top.html>.
Read section 5, "Null Pointers".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Nov 14 '05 #15

P: n/a
On Tue, 30 Dec 2003 14:07:21 GMT, pete <pf*****@mindspring.com> wrote
in comp.lang.c:
Martin Dickopp wrote:

dt*******@yahoo.com (vp) writes:
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;"


No. The former statement sets all bits of `p' to zero, which is not
necessarily a representation of the null pointer.
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(ModuleFunctions)*N );

Otherwise (if `garMF' doesn't have static storage duration)
you'll have to loop.


I disagree about the necessity of a loop.

ModuleFunction garMF[N] = {NULL};


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.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 14 '05 #16

P: n/a
Mark A. Odell wrote:

So are you saying that this isn't safe?

#include <stdlib.h>

int main(void)
{
int *pVar = malloc(1024);

if (pVar) /* <--- Not safe? */
{
free(pVar);
}

return EXIT_SUCCESS;
}


Answers already given, but I wanted to mention that this is also valid:

int *p = 0;

regardless of the object-representation of the null pointer value. This
is somewhat obvious, because even on systems where the null-pointer
value is not represented by all-bits-zero, NULL must still be defined as
a constant expression with the value 0, possibly cast to void*, so this:

int *p = NULL;

is translated by the preprocessor to something equivalent to one of the
following:

int *p = 0;

or

int *p = (void *)0;

It follows somewhat logically that things like these:

if (p)
if (p == 0)

are actually testing p against the null pointer value, whatever its
representation is.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #17

P: n/a
Jack Klein wrote:
On Tue, 30 Dec 2003 14:07:21 GMT, pete <pf*****@mindspring.com> wrote
in comp.lang.c:

ModuleFunction garMF[N] = {NULL};

I would much prefer {0} to {NULL} here.


Is {NULL} even correct here if NULL happens to be #defined with a cast
to void*?

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #18

P: n/a
"Kevin Goodsell" <us*********************@neverbox.com> wrote in message
news:ZA*******************@newsread1.news.pas.eart hlink.net...
Jack Klein wrote:
On Tue, 30 Dec 2003 14:07:21 GMT, pete <pf*****@mindspring.com> wrote
in comp.lang.c:

ModuleFunction garMF[N] = {NULL};

I would much prefer {0} to {NULL} here.


Is {NULL} even correct here if NULL happens to be #defined with a cast
to void*?


Yes. Since NULL is a null pointer constant.

6.3.2.3p4: "Conversion of a null pointer to another pointer type yields a
null pointer of that type. ...". [There is no limitation with respect to
function pointers in this regard.]

6.7.8p11 Initialization: "...the same type constraints and conversions as
for simple assignment apply,..."

6.5.16.1p1 Simple Assignment - Constraints: "... - the left operand is a
pointer and the right is a null pointer constant; ..."

6.5.16.1p2 Simple Assignment - Semantics: "In simple assignment (=), the
value of the right operand is converted to the type of the assignment
expression and replaces the value stored in the object designated by the
left operand."

I think Jack prefers {0} because it's a more consistent (and well
understood) paradigm in general.

--
Peter
Nov 14 '05 #19

P: n/a
Jack Klein wrote:

On Tue, 30 Dec 2003 14:07:21 GMT,
pete <pf*****@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 ?

--
pete
Nov 14 '05 #20

P: n/a
On Wed, 31 Dec 2003 12:46:37 GMT, pete <pf*****@mindspring.com> wrote
in comp.lang.c:
Jack Klein wrote:

On Tue, 30 Dec 2003 14:07:21 GMT,
pete <pf*****@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
Nov 14 '05 #21

P: n/a
On Tue, 30 Dec 2003 22:01:29 GMT, Kevin Goodsell
<us*********************@neverbox.com> wrote in comp.lang.c:
Jack Klein wrote:
On Tue, 30 Dec 2003 14:07:21 GMT, pete <pf*****@mindspring.com> wrote
in comp.lang.c:

ModuleFunction garMF[N] = {NULL};

I would much prefer {0} to {NULL} here.


Is {NULL} even correct here if NULL happens to be #defined with a cast
to void*?


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
Nov 14 '05 #22

P: n/a
On Wed, 31 Dec 2003 15:37:42 +1100, Peter Nilsson wrote:
I think Jack prefers {0} because it's a more consistent (and well
understood) paradigm in general.


No, he explained why,and it makes logic.
Nov 14 '05 #23

P: n/a
"stau" <st**@pretogal.pt> wrote in message
news:pa****************************@pretogal.pt...
On Wed, 31 Dec 2003 15:37:42 +1100, Peter Nilsson wrote:
I think Jack prefers {0} because it's a more consistent (and well
understood) paradigm in general.


No, he explained why,and it makes logic.


How is "{0} works in all cases..." significantly different to what I said?
It's more succinct and better phrased, I grant you, but I don't see how my
sentence runs contrary to it.

P.S. Jack's replies were not available on my news server at the time I made
the post.

--
Peter
Nov 14 '05 #24

P: n/a
Jack Klein wrote:

On Wed, 31 Dec 2003 12:46:37 GMT, pete <pf*****@mindspring.com> wrote
in comp.lang.c:
Jack Klein wrote:

On Tue, 30 Dec 2003 14:07:21 GMT,
pete <pf*****@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.


What you said, could also be used to explain a preference for
char *pointer = 0;
over
char *pointer = NULL;

Is that your preference also ?

--
pete
Nov 14 '05 #25

P: n/a
"pete" <pf*****@mindspring.com> wrote...
Jack Klein wrote:

I should have elaborated. {0} works in all cases to initialize any
static or automatic scalar or aggregate type.
What you said, could also be used to explain a preference for
char *pointer = 0;
over
char *pointer = NULL;


Not quite. Since a void* is implicitly converted to any type*, the two
examples are exactly equivalent regardless of any of the two standard
definitions of NULL.
Is that your preference also ?


My preference is the latter, but it is only a style issue, nothing else.
Nov 14 '05 #26

P: n/a
Peter Pichler wrote:

"pete" <pf*****@mindspring.com> wrote...
Jack Klein wrote:

I should have elaborated.
{0} works in all cases to initialize any
static or automatic scalar or aggregate type.


What you said, could also be used to explain a preference for
char *pointer = 0;
over
char *pointer = NULL;


Not quite.
Since a void* is implicitly converted to any type*, the two
examples are exactly equivalent regardless of any of the two standard
definitions of NULL.


Exactly quite.

ModuleFunction garMF[N] = {NULL};
and
ModuleFunction garMF[N] = {0};

are exactly equivalent regardless of any of the two standard
definitions of NULL.

Is that your preference also ?


My preference is the latter,
but it is only a style issue, nothing else.


Style issues are on topic.
Reasons for prefering one style over another
which involve legibility and maintainability,
are the more interesting ones.

--
pete
Nov 14 '05 #27

P: n/a
"pete" <pf*****@mindspring.com> wrote...
Jack Klein wrote:

I should have elaborated. {0} works in all cases to initialize any
static or automatic scalar or aggregate type.
What you said, could also be used to explain a preference for
char *pointer = 0;
over
char *pointer = NULL;


Not quite. Since a void* is implicitly converted to any type*, the two
examples are exactly equivalent regardless of any of the two standard
definitions of NULL.
Is that your preference also ?


My preference is the latter, but it is only a style issue, nothing else.
Nov 14 '05 #28

P: n/a
"pete" <pf*****@mindspring.com> wrote...
Jack Klein wrote:

I should have elaborated. {0} works in all cases to initialize any
static or automatic scalar or aggregate type.
What you said, could also be used to explain a preference for
char *pointer = 0;
over
char *pointer = NULL;


Not quite. Since a void* is implicitly converted to any type*, the two
examples are exactly equivalent regardless of any of the two standard
definitions of NULL.
Is that your preference also ?


My preference is the latter, but it is only a style issue, nothing else.

Nov 14 '05 #29

P: n/a
"pete" <pf*****@mindspring.com> wrote...
Peter Pichler wrote:
"pete" <pf*****@mindspring.com> wrote...
Jack Klein wrote:

What you said, could also be used to explain a preference for
char *pointer = 0;
over
char *pointer = NULL;


Not quite.
Since a void* is implicitly converted to any type*, the two
examples are exactly equivalent regardless of any of the two standard
definitions of NULL.


Exactly quite.
ModuleFunction garMF[N] = {NULL};
and
ModuleFunction garMF[N] = {0};
are exactly equivalent regardless of any of the two standard
definitions of NULL.


Only if garMF[N] is a pointer.

If I remember correctly, the thread started with explicit initialization
of struct members with memset, {NULL} or {0}. Of those three, memset can
only be portably used if the struct is a wrapper for an usigned char array,
anything else may lead to a UB. {NULL} can only be used if the first member
of such struct is a pointer. {0}, however, can be used in any context.
Is that your preference also ?


My preference is the latter,
but it is only a style issue, nothing else.


Style issues are on topic.
Reasons for prefering one style over another
which involve legibility and maintainability,
are the more interesting ones.


I didn't say it was not on-topic. Whether or not it is a /good/ topic
is quite a different question though ;-)

Peter
Nov 14 '05 #30

P: n/a
Peter Pichler wrote:

"pete" <pf*****@mindspring.com> wrote...
Peter Pichler wrote:
"pete" <pf*****@mindspring.com> wrote...
> Jack Klein wrote:
>
> What you said, could also be used to explain a preference for
> char *pointer = 0;
> over
> char *pointer = NULL;

Not quite.
Since a void* is implicitly converted to any type*, the two
examples are exactly equivalent regardless
of any of the two standard definitions of NULL.


Exactly quite.
ModuleFunction garMF[N] = {NULL};
and
ModuleFunction garMF[N] = {0};
are exactly equivalent regardless of any of the two standard
definitions of NULL.


Only if garMF[N] is a pointer.


garMF[0].func1, is a pointer, which is plain from the code
that you snipped, so how does "Only if" enter into it?

--
pete
Nov 14 '05 #31

P: n/a
On Thu, 01 Jan 2004 16:19:17 +1100, Peter Nilsson wrote:
"stau" <st**@pretogal.pt> wrote in message
news:pa****************************@pretogal.pt...
On Wed, 31 Dec 2003 15:37:42 +1100, Peter Nilsson wrote:
> I think Jack prefers {0} because it's a more consistent (and well
> understood) paradigm in general.


No, he explained why,and it makes logic.


How is "{0} works in all cases..." significantly different to what I said?
It's more succinct and better phrased, I grant you, but I don't see how my
sentence runs contrary to it.


It's clear to all that Jack was generalizing.

struct some { int *a, *b, c } = {NULL}
Will work.

struct some2 { int a, *b, *c } = {NULL}
This may or may not work, depending on the definition of NULL (ie. if
it'just 0 (zero) it will work, if it's ((void *) 0) it'll not work.

So, I kind of agree that it's good idea to use 0 to initialize structs,
but of course, this was 1F/2*OT in this thread.
I personally like to use the explicit NULL when I'm using pointers.

Best regards,
Stau no Preto.
Nov 14 '05 #32

This discussion thread is closed

Replies have been disabled for this discussion.