0

hi guys
i don't understand the following clause.
LargeStruct *s=(LargeStruct *)0;


here LargeStruct is defined as following:
struct LargeStruct
{
double bigd1[MAX_ELEMENTS];
double bigd2[MAX_ELEMENTS];
double bigd3[MAX_ELEMENTS];
double bigd4[MAX_ELEMENTS];
};
could you explain that for me?thanks.why not just:
LargeStruct * s?

3
Contributors
7
Replies
8
Views
12 Years
Discussion Span
Last Post by wu7jian
0

>i don't understand the following clause.
It initializes s to a null pointer. The cast is not needed, which suggests that the author really doesn't know what he's doing:

LargeStruct *s = 0; // Works just fine and is easier to read

>why not just: LargeStruct * s?
Because then the pointer would point to some random location in memory, which is a Bad Thing(TM).

0

>Is that the same as:
>LargeStruct *s = NULL;
Only if you include a header that defines the NULL macro.

1

>I didn't realize NULL wasn't part of the language itself...
It isn't a part of the language, just like cout isn't a part of the language. It's a part of the standard library. NULL is a preprocessor macro, usually defined in C++ as:

#define NULL 0

And you might see a definition in C like this:

#define NULL ( (void*)0 )
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.