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?

Recommended Answers

All 7 Replies

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

thanks narue.
well i think they are the same ,winbatch

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

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

i see.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.