* gcc question about the embedded type definitions @ 2004-12-03 6:51 Wei ZHANG 2004-12-03 9:20 ` Nathan Sidwell 0 siblings, 1 reply; 4+ messages in thread From: Wei ZHANG @ 2004-12-03 6:51 UTC (permalink / raw) To: GCC Help Hi, I have a question on embedded type definitions. If in a structure definition, another type is defined. e.g. typedef struct S1 { struct S2 { int a; } } S1; is the data type S2 visible outside S1? Originally i think it is not visible outside. But in gcc, I can declare a varible of type struct S2, and operate on it. e.g.: S2 b; b.a = 100; printf("result = %d\n", b.a); That implies the name of the structure type S2 must be unique in the C file. Am I right? Can anyone elaborate on this? Thanks! Best Regards, Zhang Wei ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gcc question about the embedded type definitions 2004-12-03 6:51 gcc question about the embedded type definitions Wei ZHANG @ 2004-12-03 9:20 ` Nathan Sidwell 2004-12-03 11:29 ` Serge Fukanchik 0 siblings, 1 reply; 4+ messages in thread From: Nathan Sidwell @ 2004-12-03 9:20 UTC (permalink / raw) To: Wei ZHANG; +Cc: GCC Help Wei ZHANG wrote: > Hi, > > I have a question on embedded type definitions. > > If in a structure definition, another type is defined. e.g. > > typedef struct S1 { > struct S2 { > int a; > } > } S1; > > is the data type S2 visible outside S1? Originally i think it is not > visible outside. in C it is visible, in C++ it is not. in C it declares a field of the outer struct, in C++ it declares a nested member. Your example is neither C not C++ though, as it is missing at least a semi colon. nathan -- Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gcc question about the embedded type definitions 2004-12-03 9:20 ` Nathan Sidwell @ 2004-12-03 11:29 ` Serge Fukanchik 2004-12-03 11:38 ` Nathan Sidwell 0 siblings, 1 reply; 4+ messages in thread From: Serge Fukanchik @ 2004-12-03 11:29 UTC (permalink / raw) To: Nathan Sidwell; +Cc: Wei ZHANG, GCC Help Nathan Sidwell wrote: > in C it is visible, in C++ it is not. ?! In C++ all members of `struct' are public by default and hence fully accessible. You have to explicitly say `private:'. On the other side all members of `class' are private by default. You can not access them unless you say `public:' --- Serge ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gcc question about the embedded type definitions 2004-12-03 11:29 ` Serge Fukanchik @ 2004-12-03 11:38 ` Nathan Sidwell 0 siblings, 0 replies; 4+ messages in thread From: Nathan Sidwell @ 2004-12-03 11:38 UTC (permalink / raw) To: Serge Fukanchik; +Cc: Wei ZHANG, GCC Help Serge Fukanchik wrote: > Nathan Sidwell wrote: > >> in C it is visible, in C++ it is not. > > ?! In C++ all members of `struct' are public by default > and hence fully accessible. You have to explicitly say `private:'. you have to qualify their names -- they are not visible in the global namespace. The question was about their visibility not their accessibility. nathan -- Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-12-03 11:38 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2004-12-03 6:51 gcc question about the embedded type definitions Wei ZHANG 2004-12-03 9:20 ` Nathan Sidwell 2004-12-03 11:29 ` Serge Fukanchik 2004-12-03 11:38 ` Nathan Sidwell
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).