i have some code:
char * itoa(int a)
{
char (*t)[16]=(char(*)[16])malloc(1*sizeof(char[16]));
sprintf(*t,"%d",a);
return *t;
}
// ...
mvwprintw(my_menu_win,i+1,2,itoa(i));
can i free memory from malloc, without add temporary variables?
e.g:
temp=itoa(i);
mvwprintw(my_menu_win,i+1,2,temp);
free(temp);
In short: No.
To free allocated memory you need a reference to it.
If you could change your conversion API, a possible work around could be to use an externally provided buffer:
Call
itoa()this way then:Alternatively (C99 only) one could do the call to
itoa()this way:So to clean up this a macro helps: