www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [SAOC 25] improve importC weekly update 13

reply Emmanuel <emmankoko519 gmail.com> writes:
Hi all,

This week, I fixed complex compile time error when used in tenary 
operators.


```

void foo() {
     double *a;
     double _Complex *b;
     double _Complex zden;
     double c, d;
     zden = c > d? b[0]: a[0];
}
```

in a tenary operator setup like this, DMD reported incompatible 
types between the `double` nd the `double _Complex`. no common 
type handler did not exist for complex types which expected for 
the `double` to be type casted to `double _Complex`.

But then this fix led to more investigations as importC uses 
complex library struct instead of the deprecated fundamental D 
complex type.  And I am still investigating other issues with 
complex numbers to see if I will need to do that transition to 
make C use fundamental complex.
Dec 15
parent reply Lance Bachmeier <no spam.net> writes:
On Monday, 15 December 2025 at 14:01:36 UTC, Emmanuel wrote:
 Hi all,

 This week, I fixed complex compile time error when used in 
 tenary operators.


 ```

 void foo() {
     double *a;
     double _Complex *b;
     double _Complex zden;
     double c, d;
     zden = c > d? b[0]: a[0];
 }
 ```

 in a tenary operator setup like this, DMD reported incompatible 
 types between the `double` nd the `double _Complex`. no common 
 type handler did not exist for complex types which expected for 
 the `double` to be type casted to `double _Complex`.

 But then this fix led to more investigations as importC uses 
 complex library struct instead of the deprecated fundamental D 
 complex type.  And I am still investigating other issues with 
 complex numbers to see if I will need to do that transition to 
 make C use fundamental complex.
Thanks for figuring this out. I was the one that filed the bug in question. It would be valuable for scientific code to have complex numbers just work with ImportC. I recall looking into this before opening the issue, but that turned out to be a rabbit hole I didn't want to go down.
Dec 15
parent Emmanuel <emmankoko519 gmail.com> writes:
On Monday, 15 December 2025 at 17:14:30 UTC, Lance Bachmeier 
wrote:
 On Monday, 15 December 2025 at 14:01:36 UTC, Emmanuel wrote:
 [...]
Thanks for figuring this out. I was the one that filed the bug in question. It would be valuable for scientific code to have complex numbers just work with ImportC. I recall looking into this before opening the issue, but that turned out to be a rabbit hole I didn't want to go down.
That's exciting to hear! for the next days, I will be actively looking into complex code and make sure they work nicely with C code.
Dec 15