Re: How static link dll msvcr120.dll?

2023-05-29 Thread novice2 via Digitalmars-d-learn

you cannot "static link dll", "d" in "dll" is "dynamic".
you can implicity or explicity load dll.

https://learn.microsoft.com/en-us/cpp/build/linking-an-executable-to-a-dll?view=msvc-170

may be you mean static link msvcr120.lib?
i am not windows guru, but you need msvcr120.lib (there is 2 
version of .lib - one small for use .dll and contain only 
reference to code in dll, other large, for static linking, 
contains all code).


to link mylib.lib you can use pragma(lib, "mylib.lib") in D code.



Re: Code duplication where you wish to have a routine called with either immutable or mutable arguments

2023-05-29 Thread Ali Çehreli via Digitalmars-d-learn

On 5/29/23 19:57, Cecil Ward wrote:

> I wish to have one routine
> that can be called with either immutable or (possibly) mutable argument
> values.

'const' should take both immutable and mutable. Can you show your case 
with a short example?


> Could I make the one routine into a template?

That could work but give 'in' parameters a try:

  https://dlang.org/spec/function.html#in-params

Ali



Re: Code duplication where you wish to have a routine called with either immutable or mutable arguments

2023-05-29 Thread Paul Backus via Digitalmars-d-learn

On Tuesday, 30 May 2023 at 02:57:52 UTC, Cecil Ward wrote:
I have often come into difficulties where I wish to have one 
routine that can be called with either immutable or (possibly) 
mutable argument values. The argument(s) in question are in, 
readonly, passed by value or passed by const reference. Anyway, 
no one is trying to write to the items passed in as args, no 
badness attempted.


When I call the routine from one place with an argument that is 
immutable and then from another that is not, or it could be 
const as well, or not, that’s when I get all kinds of type 
mismatch errors. And I certainly don’t want to pour cast-like 
type conversion operations over all the place at these problem 
occurrences. it’s surely asking for problems.


Normally you would use const for this, since a const parameter 
can accept either a mutable or an immutable argument. If const 
isn't working for you, then there's probably something else going 
on that you haven't mentioned. Can you post an example of the 
kind of code that gives you these errors?


Code duplication where you wish to have a routine called with either immutable or mutable arguments

2023-05-29 Thread Cecil Ward via Digitalmars-d-learn
I have often come into difficulties where I wish to have one 
routine that can be called with either immutable or (possibly) 
mutable argument values. The argument(s) in question are in, 
readonly, passed by value or passed by const reference. Anyway, 
no one is trying to write to the items passed in as args, no 
badness attempted.


When I call the routine from one place with an argument that is 
immutable and then from another that is not, or it could be const 
as well, or not, that’s when I get all kinds of type mismatch 
errors. And I certainly don’t want to pour cast-like type 
conversion operations over all the place at these problem 
occurrences. it’s surely asking for problems.


Could I make the one routine into a template? Even if I did, that 
would perhaps create additionally problems, since even if it all 
worked and instantiated either immutable or mutable forms of the 
routine, what happens if I have two args and they have a mixture 
of immutable and no immutable args ? So nargs * 2 ( or more) 
possibilities?


I’m out of my depth here.


Re: How can I use Linker flags using DMD?

2023-05-29 Thread Ali Çehreli via Digitalmars-d-learn

On 5/29/23 17:39, Marcone wrote:

> Can you help me static link dll msvcr120.dll in my x64 dlang program?

Sorry, I haven't been programming on Windows for a very long time now. 
:/ But there are others who program on Windows here.


Ali



Re: How get struct value by member name string ?

2023-05-29 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 30, 2023 at 01:24:46AM +, John Xu via Digitalmars-d-learn wrote:
> On Monday, 29 May 2023 at 11:21:11 UTC, Adam D Ruppe wrote:
> > On Monday, 29 May 2023 at 09:35:11 UTC, John Xu wrote:
> > > Error: variable `column` cannot be read at compile time
> > 
> > you should generally getMember on a variable
> > 
> > T t;
> > __traits(getMember, t, "name")
> > 
> > like that, that's as if you wrote t.name
> 
> It seems I can't use variable as member name:
> 
> struct T {int a; string name;}
> T t;
> string s = "name";
> writeln(__traits(getMember, t, s));
> 
> Above code fails to compile. Any help?

Short answer:

`s` must be known at compile-time.  Or more precisely, known at the time
of template expansion. In this case, use `enum`:

enum s = "name";


Long answer:
https://wiki.dlang.org/Compile-time_vs._compile-time


T

-- 
Which is worse: ignorance or apathy? Who knows? Who cares? -- Erich Schubert


Re: How get struct value by member name string ?

2023-05-29 Thread John Xu via Digitalmars-d-learn

On Monday, 29 May 2023 at 11:21:11 UTC, Adam D Ruppe wrote:

On Monday, 29 May 2023 at 09:35:11 UTC, John Xu wrote:

Error: variable `column` cannot be read at compile time


you should generally getMember on a variable

T t;
__traits(getMember, t, "name")

like that, that's as if you wrote t.name


It seems I can't use variable as member name:

struct T {int a; string name;}
T t;
string s = "name";
writeln(__traits(getMember, t, s));

Above code fails to compile. Any help?


Re: How can I use Linker flags using DMD?

2023-05-29 Thread Marcone via Digitalmars-d-learn

On Monday, 29 May 2023 at 22:48:29 UTC, Ali Çehreli wrote:

On 5/29/23 07:29, Marcone wrote:

I want send flags to linker when using dmd.exe compiler.


-L does it. Yes, -L-L can happen. :)

  https://dlang.org/dmd-linux.html

Ali


Can you help me static link dll msvcr120.dll in my x64 dlang 
program?


Re: How can I use Linker flags using DMD?

2023-05-29 Thread Ali Çehreli via Digitalmars-d-learn

On 5/29/23 07:29, Marcone wrote:

I want send flags to linker when using dmd.exe compiler.


-L does it. Yes, -L-L can happen. :)

  https://dlang.org/dmd-linux.html

Ali



Re: How get struct value by member name string ?

2023-05-29 Thread Adam D Ruppe via Digitalmars-d-learn

On Monday, 29 May 2023 at 09:35:11 UTC, John Xu wrote:

Error: variable `column` cannot be read at compile time


you should generally getMember on a variable

T t;
__traits(getMember, t, "name")

like that, that's as if you wrote t.name


How get struct value by member name string ?

2023-05-29 Thread John Xu via Digitalmars-d-learn
I saw ddbc 
(https://github.com/buggins/ddbc/blob/master/source/ddbc/pods.d) 
uses


static if (__traits(compiles, (typeof(__traits(getMember, T, 
m) {

__traits(getMember, T, m)
}

But for my experience, above code sometimes/somewhere works, 
sometimes/somewhere just doesn't:


Error: variable `column` cannot be read at compile time

Is there any friend can explain some more details?