NO

Author Topic: Stuctures  (Read 4587 times)

tpekar

  • Guest
Stuctures
« 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.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: Stuctures
« Reply #1 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()  ;)

tpekar

  • Guest
Re: Stuctures
« Reply #2 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

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: Stuctures
« Reply #3 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  ;)