[LCP]sizeof question.

David filiond at videotron.ca
Fri Sep 20 15:22:11 UTC 2002


History:
   I'm creating a structure/functions for storing and retrieving the
value of options.

Here is the structure:

struct _Options {
	char *name;
	char *value;
	struct _Options *next;
};

typedef struct _Options *OptionList;

Here is the function to initialize the list:
OptionList
InitializeOptionList (void)
{
	struct _Options *ptr;

	ptr = (struct _Options *) calloc (1, sizeof *ptr);
	if (!ptr)
		return (NULL);

	ptr->name = strdup ("@");
	ptr->value = strdup ("");

	if (!ptr->name || !ptr->value) {
		free (ptr->name);
		free (ptr->value);
		free (ptr);
		return (NULL);
	}
	ptr->next = NULL;

	return (ptr);
}

Question:
  Am I using the sizeof correctly in the calloc call?  Sould I be 
using ptr instead of *ptr?

-- 
David Filion		filiond[at]videotron[dot]ca



More information about the linuxCprogramming mailing list