Re: Dynamic changing values at a GtkTreeStore with pointers



> No, wrong. Addresses are *passed* exactly like any other type is
passed. Addresses can be *obtained* using the & operator. Hence:
>
>    char jim;
>    char * fred;
>    fred  = &jim;
>
> Means:
>
>    "jim" is a variable of type "char"
>    "fred" is a variable of type "pointer to char"
>    Assign to "fred" the value obtained by applying the "take address
>of" operation on "jim". Or "make fred point to jim" for short.

Oh yes, I understand that.
What made me crazy is because when I declare this:
armazena = gtk_tree_store_new( 	NUM_COLUNAS_DADOS,
				G_TYPE_POINTER,
				G_TYPE_POINTER,
				G_TYPE_POINTER,
				G_TYPE_POINTER
				);
I thought: "Ok then, each column will store a pointer address, so, when
I need to store one of then, I need to store it with the & operator"
Finally, when I did this, it worked:
int *a;
gtk_tree_store_set( armazena, &inter,0, &a, -1);

But, when I did this, I got it wrong and took me really long time to
figure that it was wrong here:
char *a;
gtk_tree_store_set( armazena, &inter,0, &a, -1);
The correct would be:
gtk_tree_store_set( armazena, &inter,0, a, -1);

Robert Pearce escreveu:
> On Sun, 25 Mar 2007 05:17:50 -0300 Diogo wrote:
>>  It is a little confusing to me
>> because I assume that POINTERS are address and address are passed using
>> & key.
> 
> No, wrong. Addresses are *passed* exactly like any other type is passed. Addresses can be *obtained* using the & operator. Hence:
> 
>    char jim;
>    char * fred;
>    fred  = &jim;
> 
> Means:
> 
>    "jim" is a variable of type "char"
>    "fred" is a variable of type "pointer to char"
>    Assign to "fred" the value obtained by applying the "take address of" operation on "jim". Or "make fred point to jim" for short.
> 
> Of course, C++ goes and f*£$s with your understanding by _also_ using & to mean "pass by reference", where reference *is not* the same as address. This is one of many places where C++ is a very bad OO language. Its use of "polymorphism" is horribly broken.
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
> 

-- 
Diogo F. S. Ramos



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