How to do alias to a C struct member?

dangbinghoo dangbinghoo at gmail.com
Mon Apr 22 15:50:11 UTC 2019


On Monday, 22 April 2019 at 13:10:45 UTC, Adam D. Ruppe wrote:
> On Monday, 22 April 2019 at 11:04:49 UTC, dangbinghoo wrote:
>> alias ifr_ifrn.ifrn_name	    ifr_name;	  /* interface name 	*/
>>
>> So, how to do alias for a C struct member?
>
>
> D doesn't support this kind of alias. There's two options:
>
> 1) just write the full name in the code.
>
> ifreq ifr;
>
> ifr.ifr_ifrn.ifrn_name /* instead of ifr.ifrn_name */
>
> or, if you are linking in the D module containing the 
> translated headers (if you don't link it in, this will cause 
> missing symbol linker errors!)
>
> 2) write ref property functions to get to it, using ufcs for 
> the middle. So replace that *alias* line with:
>
> @property ref ifr_name(ifreq this_) { return 
> this_.ifr_ifrn.ifrn_name; }
>
>
> Then you should be able to use it the same way as in C.

OK, I'd prefer with option 2.
thank you in advance!


More information about the Digitalmars-d-learn mailing list