December 11, 2013 Re: How to handle nested structs when converting C headers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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?
|
December 12, 2013 Re: How to handle nested structs when converting C headers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | 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. T -- It is of the new things that men tire --- of fashions and proposals and improvements and change. It is the old things that startle and intoxicate. It is the old things that are young. -- G.K. Chesterton |
December 12, 2013 Re: How to handle nested structs when converting C headers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Thu, 12 Dec 2013 00:04:07 -0000, H. S. Teoh <hsteoh@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/ |
December 12, 2013 Re: How to handle nested structs when converting C headers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | Regan Heath:
> 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.
It's mostly a matter of style, but here I prefer a little more the nested form. It's syntactically closer to the original C file, for a D programmer "static struct" has a known and clear meaning, and putting the structs inside the other keeps the global namespace clean of those inner names. Like with nested functions putting names inside other scoped helps the programmer see they are just needed there.
Bye,
bearophile
|
December 12, 2013 Re: How to handle nested structs when converting C headers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On 2013-12-11 23:45, Gary Willoughby wrote: > How to handle nested structs when converting C headers? > > In the following snippet i'm currently converting, how would you convert > the nested typed union and structures? Would you declare them separately > then use their types in the Tcl_Obj struct? or is there a nice way in D > to nest them like C? Convert using DStep[1] and see what happens :) [1] https://github.com/jacob-carlborg/dstep -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation