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: Piotr Sulecki <Piotr.Sulecki@xxxxxxxxxxxxx>
Cc: Ben Webb <ben@xxxxxxxxxxxxxxxxxxxxxx>, "Per I. Mathisen" <Per.Inge.Mathisen@xxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: newbie C question
From: Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 5 Mar 2002 14:46:15 +0100
Reply-to: rf13@xxxxxxxxxxxxxxxxxxxxxx

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


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