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

[Freeciv-Dev] newbie C question

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] newbie C question
From: "Per I. Mathisen" <Per.Inge.Mathisen@xxxxxxxxxxx>
Date: Tue, 5 Mar 2002 12:46:29 +0100 (MET)

Will pointers always be initialized to NULL? I seem to remember reading
that somewhere, but maybe that wasn't about C :)

In other words, are these safe:

char *ptr;
if (ptr!=NULL) free(ptr);

or

char *ptr;
fc_realloc(ptr, 4096);

or

struct mystruct *ptr;
fc_malloc(ptr, 11 * sizeof(&ptr));
if (ptr[0]->ptr!=NULL) free(ptr[0]->ptr);

If not, how about this:

struct mystruct *ptr;
fc_calloc(ptr, 11 * sizeof(&ptr));
if (ptr[0]->ptr!=NULL) free(ptr[0]->ptr);

Yours,
Per

"What we anticipate seldom occurs: but what we least expect generally
happens." -- Benjamin Disraeli



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