How can we call a func template instance using the Mars vendor already ?
user1234
user1234 at 12.de
Thu Feb 19 18:08:24 UTC 2026
On Thursday, 19 February 2026 at 16:54:11 UTC, monkyyy wrote:
> 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;
> }
> ```
That's a nice reduction. We are at the point where we agree that
```d
module onlineapp;
int ok(int i:1)(){return 1;}
enum mangle=ok!1.mangleof;
mixin("extern(C) int "~mangle~"();");
void OK()
{
asm
{
call _D9onlineapp__T2okHVii1ZQjFNaNbNiNfZi;
}
}
int main()
{
OK();
return 0;
}
```
is just fine. But if you remove the default static int argument:
```
module onlineapp;
int ok(int i)(){return i;}
enum mangle=ok!1.mangleof;
mixin("extern(C) int "~mangle~"();");
void OK()
{
asm
{
call _D9onlineapp__T2okHVii1ZQjFNaNbNiNfZi;
}
}
int main()
{
OK();
return 0;
}
```
you run into the same problem as the one I pointed in the initial
message.
> Error: function `onlineapp.OK` label
> `_D9onlineapp__T2okHVii1ZQjFNaNbNiNfZi` is undefined
More information about the Digitalmars-d-learn
mailing list