From: Christophe A. <chr...@la...> - 2004-07-21 09:07:04
|
Forward declaration is not necessary with pointer (always a 4-byte unsigned integer for ia32), but you must use a tag name for the structure to resolve this lack of information : typedef struct Link_s { struct Link_s *next; int value; } Link; Anyway, having a typedefed structure without a tag name is something permissible but bad because we are not sure how each compiler (gcc, vc++, etc.) would be able to mangle the name of the structure for a parameter in a global function for example. If someone knows, I would be glad to know it. Regards. ----- Original Message ----- From: "Stefan Seefeld" <se...@sy...> To: "Shigeru Chiba" <ch...@is...> Cc: <ope...@li...> Sent: Tuesday, July 20, 2004 8:10 PM Subject: Re: [Opencxx-users] parse error on valid code > Hi Chiba, > > thanks for joining in ! > > Shigeru Chiba wrote: > > >>well, but as we just discovered, this doesn't work for C++ in general where > >>certain ambiguities have to be resolved using the knowledge about previously > >>declared types, variables, etc. > > > > > > Yes, but maintaining the table of type and template names is really > > complicated. For example, the parser must be able to recognize Link > > as a type name in this code snippet: > > > > typedef struct { > > Link* next; > > int value; > > } Link; > > > > (sorry if the syntax above is wrong. I haven't written C++ code for > > years. :<) > > the syntax is wrong precisely because at the point where a variable of 'Link *' > is generated nothing is known about 'Link'. The solution is to first issue a forward > declaration of 'Link'. And that would indeed solve our problem, too (as all we > want to know is that 'Link' is indeed a type, not what kind of type). > > I believe that this is true in general for C++: either a type has previously > been declared (forward declaration counts), or we have to provide hints (isn't > that why the language contains the 'typename' keyword ?) > > Kind regards, > Stefan > > > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today. > http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click > _______________________________________________ > Opencxx-users mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/opencxx-users |