translate C struct char array into D

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jul 30 16:12:46 UTC 2021


On Fri, Jul 30, 2021 at 03:41:32PM +0000, Tejas via Digitalmars-d-learn wrote:
> On Friday, 30 July 2021 at 14:40:17 UTC, Paul Backus wrote:
[...]
> > ```d
> > struct test1 {
> >     // member variables...
> > 
> >     char* data() {
> >         return cast(char*) (&this + 1);
> >     }
> > }
> > ```
> > 
> > [1]: http://port70.net/~nsz/c/c99/n1256.html#6.7.2.1p16
> 
> B-but the performance penalty of having an extra level of indirection?
> Absolutely unacceptable!!

Premature optimization.

Any optimizer worth its salt would be able to inline such a trivial
function as .data above.  Check the output of LDC -O, for example.
(Don't talk to me about dmd, if you care about performance you'd use LDC
instead.)


T

-- 
This is a tpyo.


More information about the Digitalmars-d-learn mailing list