[Freeciv-Dev] Re: newbie C question
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Ave!
> > Will pointers always be initialized to NULL?
>
> No. No variables are initialised at all in C.
I seem to recall something about static and global variables being
initialised with zeroes. But I may be wrong, or it may be
implementation-specific (I'm 99% sure Borland/Turbo C/C++ for DOS works
this way). No automatic variables are initialised, that's for sure.
> > char *ptr;
> > if (ptr!=NULL) free(ptr);
>
> Unsafe, because ptr is uninitialised. (The check is pointless
> anyway, because free(NULL) should be a no-op.)
char *ptr = NULL;
and you're safe. The same applies to the remaining examples.
BTW, can anybody tell me how standards (ANSI, C99) define the result of
malloc(0)? A NULL or a pointer to a block with the size of zero bytes? I
tried to search for C99 standard specification (I heard it was available
on the net) but found none.
PeterS.
[Freeciv-Dev] Re: newbie C question, Raimar Falke, 2002/03/05
|
|