Re: error in passing a structure in argument of a CallBack function



On Sat, 5 May 2001, D Reymond wrote:

<...>

void function_1(void)
{
..........

 struct stab psTab;

This should be 'struct stab *psTab' to declare a pointer to the struct

 psTab = (struct stab *)g_malloc(sizeof(struct stab *));

The parameter to g_malloc() should be 'sizeof(struct stab)', so it
allocates enough memory for the struct (rather than just a pointer to it).

 if ( psTab == NULL ) { printf(" pb to alloc struct \n"); exit(-1); }

The checks for NULL are not necessary for g_malloc() and friends because
they will bomb for you on error.

Hope this helps

Jonathan







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]