Languages

Menu
Sites
Language
Initializing a Evas_object type struct in tizen

I am have a struct:

typedef struct appdata {
    Evas_Object *wdn;
	Evas_Object *cf;
	Evas_Object *nf;
	Evas_Object *usrnamebtn;
	Evas_Object *usrpwbtn;
} appdata_s;

when i try to create a pointer :

appdata_s *LoginViewptr;

and try  to use it i get an error. 

How do i properly initilize a struct pointer. Normally, i would use null/ nullptr, but that doesn't work. Maybe i am not doing it correctly.

 

Edited by: Mark Stoge on 12 Mar, 2017

Responses

2 Replies
Carlos Dominguez

Hello Mark!

Did you try to initialize like that?

appdata_s ad = {0, };

Notice that i am not crating a pointer, i am creating a real structure, but empty.

Then you can do:

appdata_s *LoginViewptr = &ad;

Lets me know if was useful. Good luck!

Carlos Dominguez

Oh! I forgot, remember that appdata_s ad = {0, }; only create the variable in the stack for method scope, when you go out that method the variable is going a be destroy and access to pointer going a generate core dump.

If you want to create this structure for permanent use you should do this:

appdata_s *LoginViewptr = calloc(1, sizeof(appdata_s));

Notice I use calloc and not malloc, because calloc reserve memory as malloc but also initializo to 0 all data.

Cheers!