how to assign cl_I type to structure number
i am r.seetaram, M.Tech, C.S. i have faced the following problem: cl_I val=10; struct node { cl_I data; struct node * link; }; struct node * start=NULL; start = (struct node *) malloc(sizeof(struct node)); start->data = value; // error in this line; --------------------------------- Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.
On Jan 31, 2006, at 1:23 AM, mahesh ram wrote:
i am r.seetaram, M.Tech, C.S. i have faced the following problem: cl_I val=10; struct node { cl_I data; struct node * link; }; struct node * start=NULL; start = (struct node *) malloc(sizeof(struct node)); start->data = value; // error in this line;
At the risk of pointing out the obvious, you don't have a variable named value, but you do have one named val. rg
Hi, mahesh ram wrote:
i have faced the following problem: cl_I val=10; struct node { cl_I data; struct node * link; }; struct node * start=NULL; start = (struct node *) malloc(sizeof(struct node)); start->data = value; // error in this line;
That's because the memory of start->data is uninitialized. You have two ways to fix that: 1. Initialize the memory from the beginning by use of 'new' instead of 'malloc' (and then of course use 'delete' instead of 'free'): start = new node(); start->data = value; 2. Keep the memory uninitialized first, and initialize it later: start = (struct node *) malloc(sizeof(struct node)); new (&start->data) cl_I(value); In this case also don't forget to call the destructor of 'data' before calling free(), otherwise you have a nice memory leak. start->data.~data(); free(start); Bruno
participants (3)
-
Bruno Haible
-
mahesh ram
-
Ron Garret