Pelles C forum

C language => Expert questions => Topic started by: tpekar on January 22, 2014, 08:47:09 PM

Title: Stuctures
Post by: tpekar on January 22, 2014, 08:47:09 PM
Does anyone know if their is a way to instantiate a structure in C at runtime?  Thanks in advance.
Title: Re: Stuctures
Post by: Bitbeisser on January 22, 2014, 09:18:01 PM
Does anyone know if their is a way to instantiate a structure in C at runtime?  Thanks in advance.
Sure, that's what malloc() is for.
Code: [Select]
struct data *my_data = (struct data *)malloc(sizeof(struct data));
Ralf

PS: You also might want to check the online help for the functions free(), calloc() and realloc()  ;)
Title: Re: Stuctures
Post by: tpekar on January 23, 2014, 08:34:12 PM
Thanks Ralf.  I've done this before.  I think I was just suffering from brain rot.  Had to re-educate myself. :P
Title: Re: Stuctures
Post by: Bitbeisser on January 24, 2014, 03:01:29 AM
Thanks Ralf.  I've done this before.  I think I was just suffering from brain rot.  Had to re-educate myself. :P
Been there, done that, didn't get the T-shirt (either)....  ;D

Ralf  ;)