How can we call a func template instance using the Mars vendor already ?

monkyyy crazymonkyyy at gmail.com
Thu Feb 19 16:54:11 UTC 2026


On Thursday, 19 February 2026 at 16:43:04 UTC, user1234 wrote:
> On Thursday, 19 February 2026 at 16:30:04 UTC, monkyyy wrote:
>> On Thursday, 19 February 2026 at 16:20:58 UTC, user1234 wrote:
>>> On Thursday, 19 February 2026 at 15:37:42 UTC, user1234 wrote:
>>>> [...]
>>>> so you'll get
>>>>
>>>>> Error: function `runnable.NG` label 
>>>>> `_D8runnable__T2ngVii1ZQiFNaNbNiNfZi` is undefined
>>>>> Error: function `runnable.NG` label 
>>>>> `_D8runnable__T7ngVii2ZQnFNaNbNiNfZi` is undefined
>>>>
>>>> So to keep things simples the idea is to provide a valid 
>>>> function identifier in the asm. I've used compiler explorer 
>>>> to get the __valid__ mangled version 
>>>> (https://godbolt.org/z/WYMqMhnWG). No luck.
>>>>
>>>> Is that even possible ?
>>>
>>> The static foreach does not seem to generate the symbols in a 
>>> classic way tho...
>>>
>>>> assume  CS:.text._D8runnable__T2ngVii1ZQiFNaNbNiNfZi
>>>
>>> but on the other hand the error message is not a linker one
>>
>> nah its the asm block not having access to templates
>
> That is not the problem. Here we accept that inline assemby is 
> "lazily handled", so you cannot mix pure (in the sense of high 
> level) D language with asm. The problem is really that the 
> function identifier should be ignored until the linking phase.
>
> Remember that we have generated the right name using "compiler 
> explorer".

.mangleof is correct and should give the same result as godbolt; 
if you want to use a managle you would have to extern c it, 
otherwise it isnt a symbol

```d

// The OK part
int ok(int i:1)(){return 1;}
int ok(int i:2)(){return 2;}

enum mangle=ok!1.mangleof;
pragma(msg,mangle);
mixin("extern(C) int "~mangle~"();"); // <======

void OK()
{
     ulong r;
     asm
     {
         xor R8, R8;
         call _D9onlineapp__T2okHVii1ZQjFNaNbNiNfZi;
         add R8, RAX;
         mov r, R8;
     }
     assert(r == 1);
}
int main()
{
     OK();
     return 0;
}
```


More information about the Digitalmars-d-learn mailing list