How to handle nested structs when converting C headers?

Regan Heath regan at netmail.co.nz
Thu Dec 12 02:44:34 PST 2013


On Thu, 12 Dec 2013 00:04:07 -0000, H. S. Teoh <hsteoh at quickfur.ath.cx>  
wrote:

> On Thu, Dec 12, 2013 at 12:54:58AM +0100, Gary Willoughby wrote:
>> On Wednesday, 11 December 2013 at 23:38:13 UTC, Adam D. Ruppe wrote:
>> >On Wednesday, 11 December 2013 at 23:35:04 UTC, Gary Willoughby
>> >wrote:
>> >>   static union internalRep
>> >
>> >
>> >try
>> >
>> >static union InternalRep { /* note the capital letter */
>> >  /* snip */
>> >}
>> >InternalRep internalRep;; // still need a decl
>>
>> Right. But why use the static keyword here?
>
> Because nested structs by default carry a pointer to the containing
> struct (or scope), which means it adds extra baggage and you can't
> create the nested without also having an instance of the containing
> struct.

I would stop nesting the struct definition.  I think that is both cleaner  
and closer to the original intent - the only reason it is nested in C is  
because C allows definition and declaration that way, and D does not.   
Then you don't need static at all.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list