TypeFunction example creatiing a conversion matrix
Adam D. Ruppe
destructionator at gmail.com
Fri Oct 2 12:56:35 UTC 2020
On Friday, 2 October 2020 at 04:53:12 UTC, Stefan Koch wrote:
> You still create unnecessary symbols.
Not true.
extern(C)
void main()
{
import core.stdc.stdio;
static immutable convMatrix = "pretend matrix";
static immutable convMatrix2 = "pretend matrix 2";
printf("%s\n", convMatrix.ptr);
printf("%s\n", convMatrix2.ptr);
}
No template in sight.
$ dmd -betterC bc
$ nm bc.o
0000000000000000 t
0000000000000000 D _D2bc4mainUZ10convMatrixyAa
0000000000000010 D _D2bc4mainUZ11convMatrix2yAa
U _GLOBAL_OFFSET_TABLE_
0000000000000000 r _TMP0
000000000000000f r _TMP1
0000000000000000 W main
U printf
Or without -betterC
$ dmd bc.d
$ nm bc.o
0000000000000000 t
0000000000000008 R _D2bc12__ModuleInfoZ
0000000000000000 D _D2bc4mainUZ10convMatrixyAa
0000000000000010 D _D2bc4mainUZ11convMatrix2yAa
U _GLOBAL_OFFSET_TABLE_
0000000000000000 r _TMP0
000000000000000f r _TMP1
U __start_minfo
U __stop_minfo
U _d_dso_registry
0000000000000000 W main
U printf
> Just use the template twice with different arguments.
>
> 0000000000000000 t
> 0000000000000008 R _D2t412__ModuleInfoZ
> 0000000000000000 D _D2t44mainUZ10convMatrixyAa
> 0000000000000010 D _D2t44mainUZ11convMatrix2yAa
> U _d_dso_registry
> U _GLOBAL_OFFSET_TABLE_
> 0000000000000000 W main
> U printf
> U __start_minfo
> U __stop_minfo
> 0000000000000000 r _TMP0
> 0000000000000142 r _TMP1
Absolutely identical. An eponymous template resolving to an enum
of a common type is indistinguishable to a literal of that type.
It does *not* generate anything extra for nested helper functions
in there.
More information about the Digitalmars-d
mailing list