www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Tuples in LDC - why it does this?

reply arandomonlooker <shdkahdkhhhhhii gmail.com> writes:
So, i have created this program that unpacks a tuple, as a form 
of error handling (betterC). An error started to pop-up. This is 
a simple program that replicates it:

```
import std.typecons;
import std.meta;

Tuple!(int, int, int) iAMfunction() {
     return tuple(1, 2, 3);
}
int main() {
     int a, b, c;
     AliasSeq!(a, b, c) = iAMfunction();
     return 0;
}
```

In DMD, this program compiles. But, in LDC this displays an error 
(i used Godbolt's latest versions for both compilers, and i used 
betterC mode for both):

```
/opt/compiler-explorer/ldc1.29.0/ldc2-1.29.0-linux-x86_64/bin/../import/core/intern
l/entrypoint.d(39): Error: only one `main` allowed. Previously found `main` at
<source>(8)
ASM generation compiler returned: 1
/opt/compiler-explorer/ldc1.29.0/ldc2-1.29.0-linux-x86_64/bin/../import/core/intern
l/entrypoint.d(39): Error: only one `main` allowed. Previously found `main` at
<source>(8)
Execution build compiler returned: 1
```

This error disappears when i delete the -betterC switch from the 
command invokation. Is this a bug? I'm not sure. That's why i ask 
before filing a bug report.
Thank you all in advance.
Jun 13 2022
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
Works in both with -betterC as per spec:

```d
import std.typecons;
import std.meta;

Tuple!(int, int, int) iAMfunction() {
     return tuple(1, 2, 3);
}

extern(C) int main() {
     int a, b, c;
     AliasSeq!(a, b, c) = iAMfunction();
     return 0;
}
```
Jun 13 2022
parent arandomonlooker <shdkahdkhhhhhii gmail.com> writes:
On Tuesday, 14 June 2022 at 03:15:50 UTC, rikki cattermole wrote:
 Works in both with -betterC as per spec:

 ```d
 import std.typecons;
 import std.meta;

 Tuple!(int, int, int) iAMfunction() {
     return tuple(1, 2, 3);
 }

 extern(C) int main() {
     int a, b, c;
     AliasSeq!(a, b, c) = iAMfunction();
     return 0;
 }
 ```
Thank you. I'm a newbie to the language, i make a lot of mistakes with it, as you can see.
Jun 13 2022