News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Stuctures

Started by tpekar, January 22, 2014, 08:47:09 PM

Previous topic - Next topic

tpekar

Does anyone know if their is a way to instantiate a structure in C at runtime?  Thanks in advance.

Bitbeisser

Quote from: 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.
Sure, that's what malloc() is for.
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()  ;)

tpekar

Thanks Ralf.  I've done this before.  I think I was just suffering from brain rot.  Had to re-educate myself. :P

Bitbeisser

Quote from: 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
Been there, done that, didn't get the T-shirt (either)....  ;D

Ralf  ;)