Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Re: newbie C question
Home

[Freeciv-Dev] Re: newbie C question

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Ben Webb <ben@xxxxxxxxxxxxxxxxxxxxxx>
Cc: "Per I. Mathisen" <Per.Inge.Mathisen@xxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: newbie C question
From: Piotr Sulecki <Piotr.Sulecki@xxxxxxxxxxxxx>
Date: Tue, 05 Mar 2002 13:17:22 +0100

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.


[Prev in Thread] Current Thread [Next in Thread]