Re: Is there a way to mark a dub package as linux only?

2022-09-27 Thread Ahmet Sait via Digitalmars-d-learn
On Monday, 26 September 2022 at 20:57:06 UTC, Christian Köstlin 
wrote:

Or posix only? Or not windows?

Kind regards,
Christian


Not necessarily a dub solution but you can do something like this:
```d
version(Posix) { }
else
static assert(0, "Unsupported platform.");
```
This will result in a compiler error while targetting a non-posix 
platform.


How to profile compile times of a source code?

2021-01-30 Thread Ahmet Sait via Digitalmars-d-learn
I'm looking for ways to figure out what parts of the code slows 
down the compiler other than brute force trial.


Can I use -vtemplates switch for this?
Would -v (verbose) switch helpful in some way?
How would I know if my bottleneck is ctfe or templates?
How do the compiler devs approach this issue?

I'm interested in all kinds of tricks to the point of debugging 
the compiler itself although anything less complicated would be 
appreciated.


Re: Building Win32 application via dub

2020-04-29 Thread Ahmet Sait via Digitalmars-d-learn
Though the program built with dub is now crashing at runtime 
when calling `writeln` within the `WinMain` block.


Back then when I was trying to use writeln (or any standard 
output function like printf)in a non-console app in Windows it 
used to crash, I don't know exact reason behind it but you might 
want to use AllocConsole to workaround it.


If the same code works fine with -m32 but not -m32mscoff (or 
-m64) then I have no idea.


Re: exporting function from betterc to windows dll

2020-03-15 Thread Ahmet Sait via Digitalmars-d-learn

On Saturday, 14 March 2020 at 20:53:45 UTC, Abby wrote:
I would like to export some functions from my bettec dll for 
dotnet core application in windows.



You can check my library documentation to understand how to do 
some fancy interop between C# and D: 
https://github.com/ahmetsait/IDL/wiki


Should probably write a detailed blog post about that some time :/


Re: How Different Are Templates from Generics

2019-10-11 Thread Ahmet Sait via Digitalmars-d-learn
On Friday, 11 October 2019 at 17:50:42 UTC, Jonathan M Davis 
wrote:
Generic functions and types operate on Object underneath the 
hood. If you have Container and Container, you really 
just have Container with some syntactic niceties to 
avoid explicit casts. You get type checks to ensure that 
Container isn't given a Bar unless Bar is derived from 
Foo, and the casts to and from Object when giving 
Container a Foo are taken care of for you, but it's still 
always Container underneath the hood.


In the case of Java, the type of T in Container or foo() 
is truly only a compile time thing, so the bytecode only has 
Container and no clue what type is actually supposed to 
be used (the casts are there where the container or function is 
used, but the container or function has no clue what the type 
is; it just sees Object). That makes it possible to cheat with 
reflection and put something not derived from Foo in 
Container but will then usually result in runtime failures 
when the casts the compiler inserted are run. C# doesn't have 
that kind of type erasure in that the information that 
Container contains Foo rather than Object is maintained at 
runtime, but you still have a Container. It's just a 
Container with some metadata which keeps track of the 
fact that for this particular object of Container, 
Object is always supposed to be a Foo. As I'm a lot less 
familiar with C# than Java, I'm not all that familiar with what 
the practical benefits that gives are, though I'd expect that 
it would mean that reflection code would catch when you're 
trying to put a Bar into Container and wouldn't let you.


Note that for generics to work, they have to a common base 
type, and you only ever get one version of a generic class or 
function even if it gets used with many different types derived 
from Object. For a primitive type like int or float (as well as 
for structs in the case of C#), they have to be put into a type 
derived from Object in order to be used with generics (as I 
expect you're aware, C# calls this boxing and unboxing). 
Templates don't act like this at all.


Unlike Java, C# actually does generate different code pieces for 
different value types [1] and reuses the same generated code for 
reference types.


[1] 
https://alexandrnikitin.github.io/blog/dotnet-generics-under-the-hood/