Re: [gtk-list] RE: hashtable corrupting data???



DROUIN Antoine STNA 7SB K232 p5766 wrote:
> 
> >hello.
> >
> >I'm trying to store datas in a g_hashtable. As soon as i do the g_hash_table_insert, my data
> >seems to be corrupted. I've attached the program.


> typedef long Position[4];


> void
> position_dump(Position *this) {
>   int i, j;
>   for (i=0; i<4; i++)
>     for (j=0; j<32; j++)
>       if ((*this[i]) & (1<<j))
>         printf("%d ", i * 32 + j);
>   printf("\n");
> }


Your Position typedef is a bit unusual and I think it is causing problems.
This line:

      if ((*this[i]) & (1<<j))

should really be:

      if (((*this)[i]) & (1<<j))

since [] has higher precedence than *. It is currently assuming
you want the ith element in an array of Position elements, when
you really want the ith element in the array of longs in the
Position. (I think!)

You'll probably have less problems if you use a struct for
Position instead.

Damon




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