LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

command "new" under Labwindows/cvi

Is there any command that fits to the "new" command under Ansi C to build a new pointer to a struct.


typedef struct self
{ int i;
struct self *next;} link;


void main (void)
{
....

if (!(hilf = new link)) exit(1);

....
}
0 Kudos
Message 1 of 3
(2,663 Views)
Use the malloc() or calloc() functions, e.g.

if (!(hilf = (link *)malloc(sizeof(link)))) exit(1);

And the free() function to free memory again.
--
Martin
Certified CVI Developer
0 Kudos
Message 2 of 3
(2,663 Views)
new and delete are C++ operators.
malloc(), calloc(), and free() are ANSI C functions.
Use sizeof() to determine how much memory to malloc() or calloc().

Try something like this.

struct self
{
int i;
struct self *next;
};

void main (void)
{
struct self *hilf;
....
hilf->next = (struct self *) malloc (sizeof( struct self));
if (hilf->next == NULL)
exit(1);
else
/* add null at the end of the list */
(hilf->next)->next = (struct self *) NULL;
....
}
Message 3 of 3
(2,663 Views)