C structure as a data type -


i want able this:

typedef struct {     char* c_str;  } string;  string s = "hello"; 

is possible in way?

i know possible this:

typedef struct {     char* c_str;  } string;  string s = { "hello" }; 

but not curly brackets when 1 member variable.

you use typedef instead of struct:

typedef char* string; string s = "hello"; 

but const string make pointer const, , not pointed-to data. const string s equivalent char* const s. solution may define additional type const strings:

typedef char* string; typedef const char* const_string; 

for original struct, same true. (c++ has same "problem", why has iterator , const_iterator in container types.)

an advantage of typedef pointer type can type

string s1, s2, s3; 

instead of

char *s1, *s2, *s3; 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -