Re: Why this compiles?

2023-11-26 Thread Adam D Ruppe via Digitalmars-d-learn

On Sunday, 26 November 2023 at 21:45:21 UTC, Antonio wrote:
In this example,  ```a``` and ```b``` vars are not of the same 
type and don't implement the same interface.  **why 
```assert(a==b)``` compiles?**


They're both subclasses of Object and inherit a generic opEquals 
from that base.


Why this compiles?

2023-11-26 Thread Antonio via Digitalmars-d-learn
In this example,  ```a``` and ```b``` vars are not of the same 
type and don't implement the same interface.  **why 
```assert(a==b)``` compiles?**



```d
interface IOpt(T) {
  bool opEquals(const IOpt!T) const @safe pure;
}

class None(T) : IOpt!T {
  bool opEquals(const IOpt!T other) const @safe pure => true;
}

void main() {
  auto a = new None!int();
  auto b = new None!string();

  assert(a==b);
}
```





Re: mixin under -betterC

2023-11-26 Thread Basile B. via Digitalmars-d-learn

On Thursday, 23 November 2023 at 16:33:52 UTC, DLearner wrote:
Code below is intended to test simple mixin with lambda 
function under -betterC.
Works with full-D, but fails with 'needs GC' errors under 
-betterC.


Why is this so, bearing in mind the concatenations are executed 
at

compile, not run, time?
```
// Test harness

   extern(C) void main() {
  import core.stdc.stdio : printf;
  import testmod;

  bool FirstVarGreater;
  int Var_A = 4;
  int Var_B = 3;


  FirstVarGreater = mixin(mxnTest("Var_A", "Var_B"));
  if (FirstVarGreater) {
printf("First Var is Greater\n");
  } else {
printf("First Var is not Greater\n");
  }
   }


// testmod

string mxnTest(string strVar1, string strVar2) {
   return `(int Var1, int Var2) {
  if (Var1 > Var2) {
 return true;
  } else {
 return false;
  }
   }(` ~ strVar1 ~ `,` ~ strVar2 ~ `)`;
}
```


You've been explained the reason why that does not work, note 
however that it's not hopeless see


- 
https://forum.dlang.org/thread/ahqnylrdftmmvtyvo...@forum.dlang.org

- https://github.com/dlang/dmd/pull/15636

unfortunately the PR is stalled since two months.


Re: Compiling an app to a single binary - possible?

2023-11-26 Thread Dmitry Ponyatov via Digitalmars-d-learn
Theoretically possible but not really expected to and generally 
does not give you much over simply distributing an archive. I'd 
even discourage it because it makes impossible to delegate 
handling of static assets to reverse proxy like nginx (which is 
likely to do better job at it being specialized tool)


Is vibe-powered backend app really runs notably slower then 
`nginx` when serving static files?


I looked on D lang in web backend as a great alternative for 
mainstream servers such as `nginx` etc especially with its 
ability to serve files the the same rates or even more faster. 
Not for a large sites but mostly embedded application such as 
vending machines with local-only web interface, or powerful 
SOHO routers and home automation controllers.


Putting all files into an executable also makes it available 
directly from RAM without any caching, so `sendfile` syscall can 
be just run for them with direct data pointer, almost without 
impacting on the app does anything else.




Re: mixin under -betterC

2023-11-26 Thread Adam D Ruppe via Digitalmars-d-learn

On Thursday, 23 November 2023 at 16:33:52 UTC, DLearner wrote:

string mxnTest(string strVar1, string strVar2) {
   return `(int Var1, int Var2) {
  if (Var1 > Var2) {
 return true;
  } else {
 return false;
  }
   }(` ~ strVar1 ~ `,` ~ strVar2 ~ `)`;
}
```


This function exists at runtime. Another module could, in theory, 
import it and call it. A shared library could, in theory, export 
it. You used it at compile time, but the function is available 
for other users too.


betterC doesn't know the difference between theory and practice.


Re: mixin under -betterC

2023-11-26 Thread DLearner via Digitalmars-d-learn

On Thursday, 23 November 2023 at 17:02:58 UTC, Paul Backus wrote:
[...]
This is a known limitation: 
https://issues.dlang.org/show_bug.cgi?id=23637



[...]

Sorry to come back to this, but the reference above suggests 
_not_ a bug in the compiler.


If not a bug in the compiler, please, what is going on?
I repeat that the only possible trigger I see for the GC
are the ~ that happen at compile, not run, time.



Re: msghdr and cmsghdr mismatch for alpine musl

2023-11-26 Thread Steven Schveighoffer via Digitalmars-d-learn

On Saturday, 25 November 2023 at 05:04:57 UTC, d007 wrote:

`import core.sys.posix.sys.socket : msghdr, cmsghdr, iovec;`


`msg_iovlen`, `msg_controllen`, `cmsg_len` is ulong for x86-64 
in druntime.




in alpine musl, they are int,  socklen_t(uint), socklen_t(uint).



Is this mismatch can cause problems is I use related api ?


Yes. Mismatch of types is a really bad error for c interaction.

-Steve