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?

12 Years
Discussion Span
Last Post by wu7jian

>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).


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


>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.