[LCP]sizeof question.

Andrew Weaver Andrew.Weaver at tecnomen.fi
Fri Sep 20 16:48:32 UTC 2002


I don't think so. You have calloc'ed size of a pointer to the struct, not
the struct itself.

On Monday, September 16, 2002 5:51 PM, David [SMTP:filiond at videotron.ca]
wrote:
> 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
> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List



More information about the linuxCprogramming mailing list