[Freeciv-Dev] Re: newbie C question
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Tue, Mar 05, 2002 at 01:17:22PM +0100, Piotr Sulecki wrote:
> 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?
7.14.3 Memory management functions
... If the size of the space requested is
zero, the behavior is implementation-defined: either a null
pointer is returned, or the behavior is as if the size were
some nonzero value, except that the returned pointer shall
not be used to access an object. ...
> I tried to search for C99 standard specification (I heard it was
> available on the net) but found none.
The real standard is only available against cash. A draft version can
be downloaded here http://std.dkuug.dk/JTC1/SC22/open/n2620/
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"Using only the operating-system that came with your computer is just
like only playing the demo-disc that came with your CD-player."
[Freeciv-Dev] Re: newbie C question, Raimar Falke, 2002/03/05
|
|