Re: error: invalid uninstantiatable type `<invalid>' in cast to ...



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> But, did you (or anyone) understand what happened?

I know what is the problem (I've had it lots of times when I was new to C), but I can't explain it. I've written
something that looks like your problem and could be also a solution (without having to allocate new memory). Perhaps you
can find out what you have to change to your code (only very few lines actually)

#include <stdio.h>
#include <string.h>

int main(void)
{
	int a11 = 11, a12 = 12, a21 = 21, a22 = 22;
	int *matrix[2][2] = {
		{ &a11, &a12},
		{ &a21, &a22}
	};

	int i, j;

	for(i = 0; i < 2; ++i)
		for(j = 0; j < 2; ++j)
			printf("matrix[%d][%d] = %d @ %p\n",
					i,j, *(matrix[i][j]), matrix[i][j]);

	void *ptr = matrix; /* what you did with pacote2 */

        ...

        /* this could also be in another function where the dimension of the matrix
           is well known */
	int *new_matrix[2][2];  /* the main part! */
	memmove(new_matrix, ptr, sizeof(int[2][2]));
	for(i = 0; i < 2; ++i)
		for(j = 0; j < 2; ++j)
			printf("new_matrix[%d][%d] = %d @ %p\n",
					i,j, *(new_matrix[i][j]), new_matrix[i][j]);


	return 0;
}

Regards
Pablo


Pablo Yánez Trujillo
http://klingsor.informatik.uni-freiburg.de/
My public key: http://klingsor.informatik.uni-freiburg.de/gpg/supertux.asc


Carlos Pereira wrote:
> WOW! Dimitrov!!!
> 
> Worked perfectly!!!!
> 
> Thanks very very much!!!
> 
> But, did you (or anyone) understand what happened?
> 
> You have used another way to build a matrix (an array of arrays). Why
> not the original matrix worked?
> 
> Well, anyway, thanks a lot again!
> 
> Best regards!
> 
> Carlos
> 
> 
> 
> On Sun, Oct 26, 2008 at 6:34 PM, �ОЌО��Пв ���е�лав <bordimida mail ru> wrote:
>> On Sun, 26 Oct 2008 21:01:29 +0300, Carlos Pereira <carlao2005 gmail com>
>> wrote:
>>
>>> Is there any difference in the way c++ treats matrices, from how c treats
>>> them??
>>>
>> I try to define drops_regras with calloc and code work correctly, but may be
>> i don't understand you right:
>>
>>        GtkWidget ***drops_regras = NULL;
>>        int j;
>>        drops_regras = (GtkWidget ***)calloc(MAIN_nregras,
>> sizeof(GtkWidget**));
>>        for(j=0; j < MAIN_nregras; j++)
>>        {
>>                drops_regras[j] = (GtkWidget **)calloc(MAIN_narq_ent + 1,
>> sizeof(GtkWidget*));
>>        }
>>
>> =======================================
>> Full my example:
>>
>> void processa_sistema(GtkWidget *widget, gpointer pacote[])
>> {
>>        GtkWidget ***drops_regras = (GtkWidget ***)pacote[0];
>>        printf( "%d\n",  gtk_combo_box_get_active(
>> GTK_COMBO_BOX(drops_regras[0][0] ) ) );
>>
>> }
>>
>> int main (int argc, char* argv[])
>> {
>>        int MAIN_nregras = 6;
>>        int MAIN_narq_ent = 3;
>>        gtk_init (&argc, &argv);
>>
>>        GtkWidget *main_table = gtk_table_new(MAIN_nregras, MAIN_narq_ent,
>> true);
>>        GtkWidget ***drops_regras = NULL;
>>        int j;
>>        drops_regras = (GtkWidget ***)calloc(MAIN_nregras,
>> sizeof(GtkWidget**));
>>        for(j=0; j < MAIN_nregras; j++)
>>        {
>>                drops_regras[j] = (GtkWidget **)calloc(MAIN_narq_ent + 1,
>> sizeof(GtkWidget*));
>>        }
>>        GtkAttachOptions gtk_attach_options_x;
>>        GtkAttachOptions gtk_attach_options_y;
>>        int coluna, linha;
>>
>>        for(coluna=0; coluna < MAIN_narq_ent + 1; coluna++)
>>        {
>>                for(linha=0; linha < MAIN_nregras; linha++)
>>                {
>>                        drops_regras[linha][coluna] = gtk_combo_box_new();
>>                        gtk_table_attach(GTK_TABLE(main_table),
>>                                GTK_WIDGET(drops_regras[linha][coluna]),
>>                                coluna + 1,
>>                                coluna + 2,
>>                                linha + 1,
>>                                linha + 2,
>>                                gtk_attach_options_x,
>>                                gtk_attach_options_y,
>>                                1, 5);
>>                }
>>        }
>>
>>        gpointer pacote2[1];
>>        pacote2[0] = drops_regras;
>>
>>        GtkWidget *button = gtk_button_new_with_label ("Press");
>>        g_signal_connect(G_OBJECT(button), "clicked",
>>                G_CALLBACK(processa_sistema), pacote2);
>>        GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
>>
>>        GtkWidget *main_window = create_window ();
>>        gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (main_table), TRUE,
>> TRUE, 0);
>>        gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (button), TRUE, TRUE,
>> 0);
>>        gtk_container_add (GTK_CONTAINER (main_window), vbox);
>>
>>        gtk_widget_show_all (main_window);
>>
>>        gtk_main ();
>> }
>>
>> --
>>
>> Dimitrov V.
>> _______________________________________________
>> gtk-list mailing list
>> gtk-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtk-list
>>
> 
> 
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAkkFATgACgkQDzf8xo+0xRVUeACfQhrMB5s52A9ZcuxZcjPOe9OU
i3UAoIx4GHgkU3Qf8iSiiWKO4DOMHAhz
=xcdi
-----END PGP SIGNATURE-----


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