Re: d strings are the bane of my existance

2021-12-05 Thread rikki cattermole via Digitalmars-d-learn

The string is not the problem.

```d
string ip_address = "192.168.1.1";
auto x = new InternetAddress(ip_address, 8008);
```

That works.

A string in D is an alias for immutable(char)[]. This is defined in 
druntime (object.d).


Immutable does cast to const implicitly, so a string argument to the 
constructor works fine as it has the same meaning.


The port however, that needs to be a ubyte/ushort to pass in and not be 
a string like you had it.


Re: Dub says that there is an invalid semVer format, but I don't see how.

2021-11-19 Thread rikki cattermole via Digitalmars-d-learn



Don't use ~> for branches.

alpha@DESKTOP-RB97SA4 /tmp/dutils
$ dub build
Invalid SemVer format: stable.0.0

alpha@DESKTOP-RB97SA4 /tmp/dutils
$ nano dub.json

alpha@DESKTOP-RB97SA4 /tmp/dutils 

$ dub build 

Performing "debug" build using 
C:\Tools\D\dmd_2.097.2\windows\bin\dmd.exe for x86_64. 

dutils 0.1.2-beta.2+commit.9.g359c59d: building configuration 
"library"... 

Error: module `package` is in file 'package.d' which cannot be read 

import path[0] = source 

import path[1] = C:\Tools\D\dmd_2.097.2\windows\bin\..\..\src\phobos 

import path[2] = 
C:\Tools\D\dmd_2.097.2\windows\bin\..\..\src\druntime\import 

C:\Tools\D\dmd_2.097.2\windows\bin\dmd.exe failed with exit code 1. 




alpha@DESKTOP-RB97SA4 /tmp/dutils 

$ cat dub.json 

{ 

"authors": [ 

"Ruby The Roobster" 

], 

"copyright": "Copyright © 2021, Ruby The Roobster", 

"description": "A collection of modules in the D Programming 
Language that people may find useful.", 

"license": "GLP-3.0", 

"name": "dutils", 

"importPaths": ["./source"], 

"sourceFiles": ["package.d"], 

"targetType": "library", 

"subPackages": [ 

{ 

"name": "sprite", 

"description": ".spr file format for images 
because I'm to lazy to use a preexisting one for sprites.", 

"targetType": "library", 

"importPaths": ["./source"], 

"sourceFiles": ["sprite.d"], 

"dependencies": { 

"dutils:skeleton": "~stable" 

} 

}, 

{ 

"name": "binom", 

"description": "Module for doing some bionomial 
work in the D Programming Language(why did I make this).",
"targetType": "library", 

"importPaths": ["./source"], 

"sourceFiles": ["binom.d"] 

}, 

{ 

"name": "skeleton", 

"description": "Module for implementing 
skeletons, e.g. a cube with criss-crossing beams to better detect 
collision.",
"targetType": "library", 

"importPaths": ["./source"], 

"sourceFiles": ["skeleton.d"] 

}, 

{ 

"name": "physics", 

"description": "A very simple and basic physics 
library.",
"targetType": "library", 

"importPaths": ["./source"], 

"sourceFiles": ["physics.d"], 

"dependencies": { 

"dutils:skeleton": "~stable" 

} 

} 

] 

} 



Re: Dub says that there is an invalid semVer format, but I don't see how.

2021-11-10 Thread rikki cattermole via Digitalmars-d-learn



On 11/11/2021 2:13 PM, Ruby The Roobster wrote:

Branch ~master: Invalid SemVer format: testing.0.0
Branch ~testing: Invalid SemVer format: testing.0.0
Version 0.1.2: Invalid SemVer format: testing.0.0


testing is a branch.

You are using ~>testing for it.

To use a branch in the SEMVER is ~branch.

https://dub.pm/package-format-json.html#version-specs


Re: Crosscompile to Windows

2021-11-08 Thread rikki cattermole via Digitalmars-d-learn



On 09/11/2021 12:44 PM, Luis wrote:
It should work with the last version of DMD : 
https://dlang.org/changelog/2.098.0.html#target


It won't.

https://github.com/dlang/dub/blob/master/source/dub/compilers/dmd.d#L111


Re: Crosscompile to Windows

2021-11-07 Thread rikki cattermole via Digitalmars-d-learn



On 08/11/2021 11:34 AM, Imperatorn wrote:

On Sunday, 7 November 2021 at 22:19:08 UTC, russhy wrote:

If i remember correctly, all you have to do is:

    dub build --arch=x86_64-pc-windows-msvc --compiler=ldc2


Is this information on dub.pm? If not, we should add it. 


This is compiler specific.

The arch triple is only supported for ldc. If you tried that with gdc it 
would error out.


Re: Average function using Variadic Functions method

2021-11-02 Thread rikki cattermole via Digitalmars-d-learn

You probably don't want to be using C variadics.

Instead try the typed one:

float mean(float[] input...) {
// you don't want to divide by zero
if (input.length == 0)
return 0;

float temp = 0;
// floats and double initialize to NaN by default, not zero.

foreach(value; input) {
temp += value;
}

return temp / input.length;
}


Re: __cpuid like in C

2021-11-01 Thread rikki cattermole via Digitalmars-d-learn



I think you are wanting this?

https://dlang.org/phobos/core_cpuid.html#.processor


Re: tkd does not build anymore after 2.096

2021-10-12 Thread rikki cattermole via Digitalmars-d-learn
The repo itself hasn't been archived as of this writing. So a PR may 
succeed.


But yeah the guy is gone by the looks.

If he is willing this could be a possible candidate for moving it to 
dlang-community although it'll need someone to shepherd it.


https://github.com/nomad-software/tkd


Re: uint overflow behaviour

2021-09-15 Thread rikki cattermole via Digitalmars-d-learn

https://dlang.org/spec/expression.html#add_expressions

"7. If both operands are of integral types and an overflow or underflow 
occurs in the computation, wrapping will happen. For example, uint.max + 
1 == uint.min, uint.min - 1 == uint.max, int.max + 1 == int.min, and 
int.min - 1 == int.max."


Re: Development of the foundation of a programming language

2021-09-12 Thread rikki cattermole via Digitalmars-d-learn



On 13/09/2021 3:21 PM, leikang wrote:
Are there any recommended books or videos to learn about the principles 
of compilation? What else should I learn besides the principles of 
compilation?


The classic book on compilers that Walter recommends is the dragon book.

https://smile.amazon.com/Compilers-Principles-Techniques-Tools-2nd-dp-0321486811/dp/0321486811

(D Language Foundation is a charity Amazon Smile recognizes).


Re: DMD compiler - warning of unused variables

2021-08-16 Thread rikki cattermole via Digitalmars-d-learn

No.

https://github.com/dlang-community/D-Scanner#implemented-checks


Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread rikki cattermole via Digitalmars-d-learn



On 15/08/2021 8:11 PM, rempas wrote:

Still don't know what "pragma" does but thank you.


pragma is a set of commands to the compiler that may be compiler specific.

In the case of the msg command, it tells the compiler to output a 
message to stdout during compilation.


Re: Any UML generators for D code?

2021-08-12 Thread rikki cattermole via Digitalmars-d-learn



On 13/08/2021 9:40 AM, russhy wrote:

also this but it's pretty old: https://github.com/rikkimax/Duml


It was a neat idea duml of mine, but I wouldn't recommend going down the 
path of CTFE for this.


Best to write a tool using dmd-fe instead.


Re: I do not understand copy constructors

2021-08-12 Thread rikki cattermole via Digitalmars-d-learn



On 12/08/2021 9:36 PM, Learner wrote:
It seems that there is no easy way to transition from a postblit to a 
copy constructor, no?


struct Foo {
this(ref Foo other) {
foreach(i, v; other.tupleof)
this.tupleof[i] = v;
}

@disable this(this);
}


Re: seeking advice: possible new @attribute to mark class' default property to avoid alias this ?

2021-08-07 Thread rikki cattermole via Digitalmars-d-learn
So a field that will automatically be resolved to as part of the 
behavior of generated toString methods.


That really isn't what alias this is used for commonly. I.e.

struct ValueReference {
private {
SomethingElse* impl;
}

bool isNull() { return impl is null; }

scope ref ValueType _get() { return impl.thingy; }

alias _get this;
}

Only the problem is, this also works for classes and whole pile of extra 
cases.


Re: Social chat in the forums

2021-08-01 Thread rikki cattermole via Digitalmars-d-learn

On 02/08/2021 9:19 AM, Brian Tiffin wrote:
Question, or suggestion.  In the Community forums, there is General and 
Announce.


Announce is only for announcements.

General is used sometimes for OT stuff, like I've congratulated Andrei 
on the birth of one of his kids (I asked prior). Or some stuff about 
COVID preparation.


Where is the preferred place to *shoot the breeze*?  D adjacent, but 
off-topic and mostly social (with the *desirable* assumption that the 
audience is all D programmers and openly nerd minded).


Generally speaking, not here.

You might want to try Discord instead, long term searchable and we do 
have an off topic channel that has been used for discussions about 
things like electrical engineering. Although we do try to discourage 
stuff like political discussion in there due to the potential conflict 
it can create.


Re: Two major problems with dub

2021-08-01 Thread rikki cattermole via Digitalmars-d-learn



On 02/08/2021 5:18 AM, Alain De Vos wrote:
A simple and small wrapper around for instance the C-library libpq 
should be part of the language itself and should not pull in more than 
libpq itself.


Just so that we are all using the same terminology.

A binding defines the functions and types as per the external libraries 
headers.
It may be dynamically loaded and require a loader also, there is no 
bloat for this.


A wrapper uses a binding but makes it more D friendly or even @safe. I 
think based upon your description that you are looking for a binding not 
a wrapper.


The only binding I could find was derelictpq which hasn't been updated 
to bindbc (not that it should matter too much). 
https://github.com/DerelictOrg/DerelictPQ


Re: GREETINGS FROM iSTANBUL

2021-08-01 Thread rikki cattermole via Digitalmars-d-learn

It appears you are using the wrong lowercase character.

https://en.wikipedia.org/wiki/Dotted_and_dotless_I

From a quick experiment, it appears std.uni is treating the upper case 
dotted I's lower case as a grapheme. Which it probably shouldn't be as 
there is an actual character for that.


We might need to update our unicode database... or something.


Re: How to put an arbitrary string to clipboard in D?

2021-07-31 Thread rikki cattermole via Digitalmars-d-learn



On 01/08/2021 6:30 AM, tastyminerals wrote:
So I thought there may be a way in D to communicate with the system 
clipboard...


No, this requires a windowing library and yes a window to do it 
(depending on the windowing system and even the desktop environment).


Re: How to put an arbitrary string to clipboard in D?

2021-07-30 Thread rikki cattermole via Digitalmars-d-learn



On 31/07/2021 7:33 AM, tastyminerals wrote:
I made a GUI app using tkd library. I am reading the string from one of 
the app widgets and would like to put it into the clipboard. Does anyone 
have an idea how to copy a string to the clipboard in D?


copyText on a Text widget appears to do what you want.

https://github.com/nomad-software/tkd/blob/9ca40d117649bb9a9db108d8f92e92870b9dc77e/source/tkd/widget/text.d#L477

https://wiki.tcl-lang.org/page/tk_textCopy


Re: enum true, or 1

2021-07-21 Thread rikki cattermole via Digitalmars-d-learn



On 22/07/2021 3:44 PM, Brian Tiffin wrote:
What is the preferred syntax for simple on/off states?  Did I read that 
D was moving to strictly 1 and 0 literals instead of true/false on/off 
yes/no?


This is the first time I'm hearing about it, so almost certainly no.


Re: Creating immutable arrays in @safe code

2021-07-17 Thread rikki cattermole via Digitalmars-d-learn



On 18/07/2021 12:56 AM, Dennis wrote:

I don't know whether the spec or code is correct.


Unless otherwise specified, the code is authoritative.


Re: Module import failing after $ dub add mypackage

2021-07-16 Thread rikki cattermole via Digitalmars-d-learn

On 17/07/2021 3:31 AM, Scotpip wrote:

In dub.sdl I see: ```dependency "msgpack-d" version="~>1.0.3"```

In dub.selections.json I see:

```
{
 "fileVersion": 1,
 "versions": {
     "msgpack-d": "1.0.3"
 }
}
```



Okay, its been added to your dub project. So far so good.


When I try to import the msgpack  into my app.d main file, I get the error:

```
$ Error: module `msgpack` is in file 'msgpack.d' which cannot be read
   import path[0] = C:\D\dmd2\windows\bin64\..\..\src\phobos
   import path[1] = C:\D\dmd2\windows\bin64\..\..\src\druntime\import
```


This should be in source/app.d


I get similar errors whether I build with dub, dmd or rdmd.


dmd and rdmd do not understand dub packages or anything else. They are 
the compiler. Only use dub and if you want to change compiler you tell 
dub this.


The file msgpack.d which the build is searching for doesn't appear to be 
on my system.


msgpack-d doesn't have a file named msgpack.d. It does have a package.d 
file inside its msgpack directory which functions as this.


You should find it under %APPDATA%/dub

``$ dub build`` inside of ``myproject`` should work.


Re: Documentation

2021-07-15 Thread rikki cattermole via Digitalmars-d-learn

Different doc generators, same source.

DDOC (phobos) and DDOX (library).

There is also adrdox[0] whose site does dub libraries also.

[0] https://dpldocs.info/


Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rikki cattermole via Digitalmars-d-learn



On 10/07/2021 2:51 AM, rempas wrote:
The file can be found quickly 
[here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) 
or in your system if you want. Now the question is, why isn't there an 
"open" function for the equivalent system call? "close", "write", "read" 
etc. all exist. Anyone knows what's going on with open?


This is easily explained.

open is not declared to be defined in unist.h[0]

You may be wanting fopen from stdio.h[1]

Or open from fcntl.h[2]

[0] https://man7.org/linux/man-pages/man0/unistd.h.0p.html
[1] https://man7.org/linux/man-pages/man0/stdio.h.0p.html
[2] https://man7.org/linux/man-pages/man0/fcntl.h.0p.html


Re: Download a file into array (using std.net.curl.download)

2021-07-07 Thread rikki cattermole via Digitalmars-d-learn



On 07/07/2021 11:54 PM, z wrote:

On Wednesday, 7 July 2021 at 10:27:47 UTC, notna wrote:

On Windows:
```
::> dmd curl_get.d
::> .\curl_get.exe

object.Error@(0): Access Violation

0x0283CA66
0x0041DE8D
0x004023A2
0x00402308
0x00414D33
0x00414CAD
0x00414B48
0x0040D41F
0x00402363
0x74B96359 in BaseThreadInitThunk
0x773887A4 in RtlGetAppContainerNamedObjectPath
0x77388774 in RtlGetAppContainerNamedObjectPath
```

Nice and helpful Error messages is on the top of our desires list, right?


On 64 bits you don't even get a stack trace or description.
Sad, i know.
If you want better i could recommend you to compile with `-g` and hook 
up a debugger, then just let it run and it should triger a breakpoint on 
0xC009(access violation).


With ldc you can turn on address sanitizer which will give you that 
information (and a LOT more!) without a debugger (but you still need -g).


http://johanengelen.github.io/ldc/2017/12/25/LDC-and-AddressSanitizer.html


Re: Unittests not firing?

2021-06-11 Thread rikki cattermole via Digitalmars-d-learn



rdmd -main -unittest file.d

```d
import std.stdio;

unittest
{
writeln("first");
}

unittest
{
writeln("second");
assert(0);
}
```

Output:

```
first
second
onlineapp.d(11): [unittest] unittest failure
1/1 modules FAILED unittests
```

The first assert to execute should kill the rest of the unittests.


Re: how to enable safeD ? dmd.conf ? dmd switch ?

2021-06-07 Thread rikki cattermole via Digitalmars-d-learn



On 08/06/2021 2:47 PM, someone wrote:

https://dlang.org/articles/safed.html
https://dlang.org/dmd-linux.html#switches
http://ddili.org/ders/d.en/functions_more.html

Neither man dmd nor man dmd.conf appear to have a related/switch setting.

Does it means safeD is achieved by placing @safe attributes all over the 
place ? Or is it achieved by setting some global switch elsewhere ? Am I 
missing something ?


SafeD is an old name given to the attributes @safe @trusted @system.

There is no switch nor any special behavior now that it has long been 
added to mainline D.


Re: Can rdmd (under Windows 10) use linker other than Optlink?

2021-05-14 Thread rikki cattermole via Digitalmars-d-learn



On 15/05/2021 9:42 AM, DLearner wrote:
I am getting 'Error 42: Symbol Undefined' while testing some (fairly) 
complex imports.


There was a reference in January to an Optlink bug that seemed like it 
could be responsible.


If rdmd can use another linker (and one was recommended), I might be 
able to test things further.


Best regards


Just don't use -m32, i.e. -m64 or -m32mscoff


Re: Thread local variables in betterC

2021-05-09 Thread rikki cattermole via Digitalmars-d-learn



On 10/05/2021 6:41 AM, Blatnik wrote:
Do thread local variables work in -betterC? Or maybe it's better to ask 
are they _supposed_ to work in -betterC?


No.

It is tied to druntime. I.e. on Linux it calls __tls_get_addr to get the 
address.


Re: dlang opengl / gl / glu /glut library.

2021-04-21 Thread rikki cattermole via Digitalmars-d-learn



On 22/04/2021 7:51 AM, Alain De Vos wrote:

import bindc.opengl;


bindbc


Re: dub commands do not run correctly.

2021-04-10 Thread rikki cattermole via Digitalmars-d-learn



dub run dfmt -- ./app.d

You passed "./app.d" to dub, not dfmt.


Re: dub commands do not run correctly.

2021-04-10 Thread rikki cattermole via Digitalmars-d-learn



On 10/04/2021 11:44 PM, Alain De Vos wrote:

In order to run commands correctly I have to put soft links :
I.e.
dfmt -> /home/x/.dub/packages/dfmt-0.13.4/dfmt/bin/dfmt
or,
dscanner -> /home/x/.dub/packages/dscanner-0.11.0/dscanner/bin/dscanner
Then ./dfmt or ./dscanner run fine.
I use freebsd as O.S.


dub does not set this up for you.


But "dub run dscanner" or "dub run dfmt" do not give the right result.
Did I miss something ?


No idea, need to see the results of the command.


Re: Extern/scope issue

2021-04-03 Thread rikki cattermole via Digitalmars-d-learn



On 04/04/2021 2:48 AM, DLearner wrote:

On Saturday, 3 April 2021 at 13:38:25 UTC, rikki cattermole wrote:


On 04/04/2021 2:34 AM, DLearner wrote:

However, changing extern(C) to extern(D) causes linker failures.
To me, that is bizarre.


extern(D) sets the ABI AND mangling.

D mangling incorporates things like the module name.


I'm sure you are correct, but extern(C) -> extern(D) in both references.
So both source streams are aware of the convention used.


https://dlang.org/spec/abi.html#name_mangling


Re: Extern/scope issue

2021-04-03 Thread rikki cattermole via Digitalmars-d-learn



On 04/04/2021 2:34 AM, DLearner wrote:

However, changing extern(C) to extern(D) causes linker failures.
To me, that is bizarre.


extern(D) sets the ABI AND mangling.

D mangling incorporates things like the module name.


Re: Extern/scope issue

2021-04-03 Thread rikki cattermole via Digitalmars-d-learn



--- main.d
module main;

extern(C) __gshared int foo;

import std;
void main()
{
import foo : func;
func;

writeln(foo);
}

--- foo.d
module foo;
extern extern(C) __gshared int foo;

void func() {
foo++;
}

The __gshared is irrelevant to it working between modules, but it is 
relevant if you want C compatibility between threads (NOTE: extern(C) 
sets mangling, otherwise the module would be encoded in its name).


Re: Extern/scope issue

2021-04-03 Thread rikki cattermole via Digitalmars-d-learn



On 03/04/2021 11:17 PM, DLearner wrote:

On Saturday, 3 April 2021 at 10:05:45 UTC, rikki cattermole wrote:

On 03/04/2021 11:01 PM, DLearner wrote:

[...]


TLS variable with D mangling, not a c global.


 [...]


That is a regular variable.
Setting the calling convention/mangling like that doesn't make any 
sense and shouldn't be allowed in context.



[...]



TLS variable with D mangling, not a c global.

Does this mean D has no equivalent of C globals?
What is the D way of doing this?


https://dlang.org/spec/attribute.html#gshared

However, you should be using the module system for accessing globals, 
rather than redeclaring them.


Re: Extern/scope issue

2021-04-03 Thread rikki cattermole via Digitalmars-d-learn

On 03/04/2021 11:01 PM, DLearner wrote:

'Testmain' imports module 'testmod'.
Both are shown below.
I expected 1,1,2,2.
I got 1,0,2,1 - which speaks to scope/extern misunderstanding

Any ideas?
Best regards

Testmain:

int xvar;


TLS variable with D mangling, not a c global.


import testmod;
void main() {
   import std.stdio;

   writeln("Entering: main");
   xvar = 1;
   writeln("xvar=", xvar);
   testsub();
   writeln("xvar=", xvar);

   writeln("Leaving: main");
}

Testmod:

void testsub() {

   extern(D) int xvar;


That is a regular variable.
Setting the calling convention/mangling like that doesn't make any sense 
and shouldn't be allowed in context.



   import std.stdio;

   writeln("Entering: testsub");
   writeln("xvar=", xvar);
   xvar = 2;
   writeln("xvar=", xvar);
   writeln("Leaving: testsub");
}





Re: Deprecation message when assigning Nullable values to an associative array.

2021-04-03 Thread rikki cattermole via Digitalmars-d-learn



On 03/04/2021 10:58 PM, rikki cattermole wrote:

Nullable has an alias this which has been deprecated.

It is due for removal (the alias this).

You can remove it manually from your copy of phobos source.

Otherwise you'll just have to wait until it is removed upstream. 
(deprecation are not errors, so you can ignore them).


So yeah, next release.

https://github.com/dlang/phobos/commit/36c309fc5fb5bc886e14bd8010e1375fa3a57d53#diff-81bed7f05cbd4e992067b7019125e6a1349ebe5098c6980b64bbbca8d5491e17


Re: Deprecation message when assigning Nullable values to an associative array.

2021-04-03 Thread rikki cattermole via Digitalmars-d-learn

Nullable has an alias this which has been deprecated.

It is due for removal (the alias this).

You can remove it manually from your copy of phobos source.

Otherwise you'll just have to wait until it is removed upstream. 
(deprecation are not errors, so you can ignore them).


Re: Check attribute against value

2021-04-02 Thread rikki cattermole via Digitalmars-d-learn
"Whether the attributes are values or types is up to the user, and 
whether later attributes accumulate or override earlier ones is also up 
to how the user interprets them."


This doesn't explain it well, but you were adding types as attributes on 
to those symbols. Not struct instances.


Re: what exactly is string length?

2021-04-01 Thread rikki cattermole via Digitalmars-d-learn



On 02/04/2021 6:10 PM, Computermatronic wrote:

On Friday, 2 April 2021 at 05:02:52 UTC, mw wrote:

Ahh, I got what I see (from writeln) is not what get string here ;-)

And I just tried:

string t = text("head-", strip(s), "-tail");

It's the same behavior.

So how can I trim the leading & trailing `\0` from the static char array?


strip only removes whitespace, not null characters. You'd have to do 
something like
```d string t = cast(string)text("head-", s, "-tail").filter!`a != 
'\0'`().array;```
I would assume there would be a better way, but I haven't been able to 
find a dedicated function for stripping null chars in std.


If you know it has null terminators you can use fromStringz.
But this is a case of you should store the length.


Re: what exactly is string length?

2021-04-01 Thread rikki cattermole via Digitalmars-d-learn



On 02/04/2021 5:51 PM, mw wrote:

Then how can I construct `t`? to make this assertion true:

    assert(t == "head-abc-tail");  // failed!


Slice it.

string t = text("head-", s[0 .. 3], "-tail");

http://ddili.org/ders/d.en/slices.html


Re: what exactly is string length?

2021-04-01 Thread rikki cattermole via Digitalmars-d-learn

On 02/04/2021 5:38 PM, mw wrote:

On Friday, 2 April 2021 at 04:36:01 UTC, rikki cattermole wrote:

On 02/04/2021 5:32 PM, mw wrote:

---
import std;
import std.conv : text;


void main()
{
    char[6] s;
    s = "abc";
    writeln(s, s.length);  // abc6, ok it's the static array's length

    string t = text("head-", s, "-tail");
    writeln(t, t.length);  // head-abc-tail16, why?

assert(t[9] == '\0');

}
---


I don't get it, what do you mean by the assertion:


assert(t[9] == '\0');


t == "head-abc-tail"


Not all characters can be printed such as NULL.

[104, 101, 97, 100, 45, 97, 98, 99, 0, 0, 0, 45, 116, 97, 105, 108]



Re: what exactly is string length?

2021-04-01 Thread rikki cattermole via Digitalmars-d-learn

On 02/04/2021 5:32 PM, mw wrote:

---
import std;
import std.conv : text;


void main()
{
    char[6] s;
    s = "abc";
    writeln(s, s.length);  // abc6, ok it's the static array's length

    string t = text("head-", s, "-tail");
    writeln(t, t.length);  // head-abc-tail16, why?

assert(t[9] == '\0');

}
---




Re: running a d compiler on the Mac Mini with an M1 chip

2021-03-26 Thread rikki cattermole via Digitalmars-d-learn

On 27/03/2021 10:51 AM, dan wrote:
Are there any d compilers that run natively on the Mac Mini with an M1 
chip?


If so, does anybody here have any experience with them that can be shared?

If not, and your machine is a mac mini, how would you go about 
programming in d on it?


TIA for any info!


Looks like latest ldc has an arm build. But both dmd and ldc should 
already work due to x86 emulation that takes place.


https://github.com/ldc-developers/ldc/releases/tag/v1.25.1


Re: can't link a code, is it a bug or my fault?

2021-03-11 Thread rikki cattermole via Digitalmars-d-learn

Try it with:

-allinst

It may just be deciding a template instance isn't required.


Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-11 Thread rikki cattermole via Digitalmars-d-learn

Pipe it to grep should work

| grep -v "__D2"


Re: How to handle exceptions right?

2021-03-08 Thread rikki cattermole via Digitalmars-d-learn

https://github.com/dlang/phobos/blob/master/std/socket.d#L190

Might be of some use to you


Re: Unexpected threads observed before main()

2021-03-01 Thread rikki cattermole via Digitalmars-d-learn

On 01/03/2021 8:02 PM, Keivan Shah wrote:
If possible, Can you also help me understand that why are the threads 
not despawned once the GC is done collecting in this example?


There was a PR about this ages ago.

But one thing to consider is that keeping threads around not doing 
anything doesn't cost anything. But spinning up will cost something.


So it is debatable if it is a good idea to get rid of them once done 
(even if delayed).


Re: Unexpected threads observed before main()

2021-02-28 Thread rikki cattermole via Digitalmars-d-learn

Do you still get them when you call your app like this?

./app --DRT-gcopt=parallel:0


Re: How can I make this work?

2021-02-28 Thread rikki cattermole via Digitalmars-d-learn

On 28/02/2021 11:05 PM, Max Haughton wrote:

Do the windows APIs expect the length in memory rather than as a parameter?


This sounds like its being sent via a user field to be passed to a callback.

I.e. event loop for a window.

In this sort of case you only get one parameter on the callback and it 
is only big enough for a pointer.


Re: How can I make this work?

2021-02-28 Thread rikki cattermole via Digitalmars-d-learn

On 28/02/2021 8:05 PM, Jack wrote:

int[] arr = [1, 2, 3];

size_t l = cast(size_t)arr.ptr;

Okay, so far so good


int[] a = cast(int[]) cast(void*) l;


Umm, you haven't specified a length?

int[] a = (cast(int*)l)[0 .. 3];

If the callback is being called (in effect under the current stack frame 
and won't escape), I would wrap the data you need in a struct and pass 
that to it instead by pointer. No need for heap allocation and gives a 
way to pass more complex data should the need arise.


Re: Class instance alignment

2021-02-20 Thread rikki cattermole via Digitalmars-d-learn

On 20/02/2021 8:13 PM, tsbockman wrote:
Well, that's just another reason not to use the GC for my current 
project, then: I'm using 256-bit AVX vectors extensively.


You can still use the GC.

You just can't use it to allocate the classes you care about.

https://dlang.org/phobos/core_memory.html#.GC.addRange


Re: Are there any containers that go with allocators?

2021-02-09 Thread rikki cattermole via Digitalmars-d-learn

https://github.com/dlang-community/containers

It uses the older design for allocators (dependency).


Re: Minimize GC memory footprint

2021-02-06 Thread rikki cattermole via Digitalmars-d-learn

On 07/02/2021 4:22 AM, frame wrote:

On Saturday, 6 February 2021 at 13:30:03 UTC, rikki cattermole wrote:


Okay, its still seeing something is alive then.


That's why I used the scope guard. I know it shouldn't have any effect 
but I want to give the GC an extra hint ;)


The GC shouldn't be aware of the scope guard. It expands out into a try 
finally block.


I've compiled and ran it under ldc. Dmd in 32bit mode is certainly 
doing something that the GC doesn't appreciate. I can reproduce it 
with -m32mscoff as well. So yeah dmd specific all right.


The sad story never ends.

But seriously are there no runtime tests before releasing the next DMD? 
The GC is a main feature of D and such things give a bad impression.


Nah, this is old. It is also bad D code.

Allocate up front and then set.

T[] buffer;
buffer.length = 1_000_000;

foreach(i, v; source[0 .. 1_000_000]) {
buffer[i] = someOp(v);
}

This will be significantly faster, as it won't require allocating more 
than once and will prevent heap fragmentation which 32bit is severely 
affected by (hence why precise GC is important for testing on this target).


Re: Minimize GC memory footprint

2021-02-06 Thread rikki cattermole via Digitalmars-d-learn

On 07/02/2021 12:38 AM, Siemargl wrote:

On Saturday, 6 February 2021 at 11:20:18 UTC, Imperatorn wrote:

On Saturday, 6 February 2021 at 09:42:38 UTC, rikki cattermole wrote:

On 06/02/2021 3:32 PM, frame wrote:

 [...]


This won't do anything.


 [...]


Don't forget to stdout.flush; Otherwise stuff can get caught in the 
buffer before erroring out.



[...]


Turn on the precise GC, 32bit is a bit too small of a range and you 
can get false positives like in this case (at least looks like it).


For reference, how does one turn on precise GC?


https://dlang.org/spec/garbage.html#gc_config

Strange things happens:
- precise scanning dont change result - OOM @ same round 27


Okay, its still seeing something is alive then.

--DRT-gcopt=help  wont show used  gc implementation, also cleanup type 
not printed


https://github.com/dlang/druntime/blob/master/src/core/gc/config.d#L36


- maxPoolSize:N  dont limit total size of GC


Shouldn't change anything, except make OOM happen faster.


- in gc:manual mode GC.collect() not releasing memory


https://github.com/dlang/druntime/blob/master/src/gc/impl/manual/gc.d#L84



When i print free GC memory, it seems to memory leaking
writefln("Usage: %.2f MiB (free %.2f MiB) / collected: %d",
     (cast(double) GC.stats.usedSize) / 1_048_576,
     (cast(double) GC.stats.freeSize) / 1_048_576, 
GC.profileStats.numCollections);

stdout.flush();


I've compiled and ran it under ldc. Dmd in 32bit mode is certainly doing 
something that the GC doesn't appreciate. I can reproduce it with 
-m32mscoff as well. So yeah dmd specific all right.


Re: Minimize GC memory footprint

2021-02-06 Thread rikki cattermole via Digitalmars-d-learn

On 06/02/2021 3:32 PM, frame wrote:

On Friday, 5 February 2021 at 22:46:05 UTC, Bastiaan Veelo wrote:


?? Do you mean no collections happen? 32bit GC should just work.


No, it doesn't - this code fails on memory allocation and works fine 
with -m64 switch:



import std.stdio;
import core.memory : GC;

void main() {

     void usage() {
     writefln("Usage: %.2f MiB / collected: %d", (cast(double) 
GC.stats.usedSize) / 1_048_576, GC.profileStats.numCollections);

     }

     void foo() {
     string[] s;

     scope (exit) {
     s.length = 0;


This won't do anything.


     }

     foreach (i; 0 .. 50_000_00) {
     s ~= "a";
     }
     }

     foreach (i; 0 .. uint.max) {
     writefln("Round: %d", i + 1);


Don't forget to stdout.flush; Otherwise stuff can get caught in the 
buffer before erroring out.



     foo();
     GC.collect();
     usage();
     }
}

...
Round: 24
Usage: 1603.57 MiB / collected: 27
Round: 25
Usage: 1691.64 MiB / collected: 28
Round: 26
Usage: 1729.50 MiB / collected: 29
Round: 27

core.exception.OutOfMemoryError@src\core\exception.d(647): Memory 
allocation failed


Turn on the precise GC, 32bit is a bit too small of a range and you can 
get false positives like in this case (at least looks like it).


Re: core.atomic for ldc.

2021-01-31 Thread rikki cattermole via Digitalmars-d-learn

The only difference between dmd, ldc and gdc (in effect) is the backend.
While druntime and Phobos will be patched for other platform targets, 
over all its the same library.


The same goes for core.atomic. You should not need to know that it has 
been patched. If you can call it and it gives you the right results, you 
can assume it worked.


Oh and $ dub build --compiler=ldc2


Re: Initializing D runtime and executing module and TLS ctors for D libraries

2021-01-27 Thread rikki cattermole via Digitalmars-d-learn

On 28/01/2021 1:16 PM, tsbockman wrote:
The documentation build on dlang.org is broken. Check the source code or 
Adam D. Ruppe's dpldocs.info for the complete documentation:

http://dpldocs.info/experimental-docs/core.thread.osthread.html


Fixed: https://issues.dlang.org/show_bug.cgi?id=21309


Re: which free operating systems have a gtkd package?

2021-01-22 Thread rikki cattermole via Digitalmars-d-learn

https://d-apt.sourceforge.io/

Or you could use dub and not worry about where its installed.

https://github.com/gtkd-developers/GtkD/wiki/Hello-World-Example-on-Ubuntu-19.10-(Linux)


Re: reference counting resources but NOT memory

2021-01-16 Thread rikki cattermole via Digitalmars-d-learn

What you are describing sounds like regular reference counting.

All resources (i.e. windows) are pinned somewhere in memory. Its just 
that you have to use special API's to destroy them rather than free.


Re: How to debug D on Linux

2021-01-13 Thread Rikki Cattermole via Digitalmars-d-learn

On Wednesday, 13 January 2021 at 13:47:55 UTC, Roguish wrote:

On Wednesday, 13 January 2021 at 13:30:48 UTC, Roguish wrote:
Anything else I need to know when debugging on Linux, without 
an IDE?


One specific question I have is: what's the difference between 
-g and -debug and -d-debug?


From LDC (ldc specific):

  --d-debug[=]   - Compile in 
debug code >=  or identified by 
  --d-version= - Compile in 
version code >=  or identified by 


From dmd:

  -debugcompile in debug code
  -debug=compile in debug code <= level
  -debug=compile in debug code identified by ident
  -version=  compile in version code >= level
  -version=  compile in version code identified by ident

Same thing.


Re: properly passing strings to functions? (C++ vs D)

2021-01-11 Thread rikki cattermole via Digitalmars-d-learn

On 12/01/2021 3:12 AM, zack wrote:

A beginner question: How to pass strings properly to functions in D?
Is there any allocation going on if just use a function as "myPrint"? In 
C++ I have often seen calls where one just passes a reference/const 
reference to a string to avoid allocation.


C++:
void myPrintCPP(const std::string& input){ ... }

D:
void myPrint(string text){ ... }
void myPrintRef(ref string text) { ... }


If you are modifying text the reference and want the caller to see the 
change, use this.


So the question is does a function call like (ref string ...) 
(myPrintRef) make any sense in D to avoid additional allocations?


There are no allocations for this.

A D-Style String could be seen as "const(char)[]"? So as it is a slice 
it already is a kind of reference to some data elsewhere? Which means 
calling a function like "myPrint" in D wouldn't cause any allocation. Is 
this correct?


alias string  = immutable(char)[];

https://github.com/dlang/druntime/blob/master/src/object.d



Re: D string to C struct fixed-size array

2021-01-03 Thread rikki cattermole via Digitalmars-d-learn

Your definition of Image is probably wrong.

You may have missed a pointer (8 bytes).


Re: D string to C struct fixed-size array

2021-01-03 Thread rikki cattermole via Digitalmars-d-learn

import std;
void main()
{
int[] a = [1, 2, 3, 4, 5];
int[3] b;

b[0 .. 3] = a[1 .. 4];
b.writeln;
}

Same principle, just remember to null terminate after slicing your 
dynamic array and assigning it to your static array.


Re: Range of dub package versions

2020-12-28 Thread rikki cattermole via Digitalmars-d-learn

$ dub upgrade

https://dub.pm/commandline.html#upgrade

dub.selections.json hasn't been deleted/upgraded so the versions would 
have gotten pinned to a known good state. Unless you change the version 
invalidating it, it most likely won't upgrade by itself.


Re: uncaught exceptions: stack trace truncated at NUL char

2020-12-13 Thread rikki cattermole via Digitalmars-d-learn

On 14/12/2020 9:56 AM, kdevel wrote:

On Sunday, 13 December 2020 at 20:25:06 UTC, KapyoniK wrote:
Is it really a bug ? \0 truncates the string, as mentionned on this 
page :

https://en.wikipedia.org/wiki/Null-terminated_string


I thought the D runtime is written in D (with D strings)?!?


String literals are null terminated by the compiler. It is very useful 
for communicating with C.


Re: MonoTimeImpl!(ClockType.normal) failed to get the frequency of the system's monotonic clock.

2020-12-13 Thread rikki cattermole via Digitalmars-d-learn
Did you initialize the D runtime before you called the D code? (assuming 
C main).


Re: Why can I call a function with mismatched parameter type?

2020-12-11 Thread rikki cattermole via Digitalmars-d-learn

On 12/12/2020 12:32 AM, rikki cattermole wrote:
Further, when the parameter name is not provided it will infer based 
upon what is passed in. In effect it is templated.


What I meant was: the type is inferred if you only provide a single 
identifier in a parameter.


Re: Why can I call a function with mismatched parameter type?

2020-12-11 Thread rikki cattermole via Digitalmars-d-learn

string is not a built in type. It is an alias defined by druntime.

https://github.com/dlang/druntime/blob/master/src/object.d#L35

int on the other hand is defined by the compiler. It understands it.

Further, when the parameter name is not provided it will infer based 
upon what is passed in. In effect it is templated.


Re: Pass enum variable as const ref arg

2020-12-04 Thread rikki cattermole via Digitalmars-d-learn

On 05/12/2020 2:42 AM, Andrey wrote:

Hm, you mean that enum variable is not a real variable?


It is not a variable. It is a constant that cannot be changed and does 
not exist in the executable.


I thought that to make CT variable you should mark it as enum (in c++ as 
constexpr).

How to do it here?


You are already doing it. This is not what you want. You want a variable 
that will pass by ref. Remove enum.


Re: Pass enum variable as const ref arg

2020-12-04 Thread rikki cattermole via Digitalmars-d-learn

On 05/12/2020 1:54 AM, Andrey wrote:

Hello,


void test(const ref string[3] qazzz) { qazzz.writeln; }

void main()
{
    enum string[3] value = ["qwer", "ggg", "v"];


That is a compile time constant (remove the enum).


    test(value);
}


Gives errors:

onlineapp.d(26): Error: function onlineapp.test(ref const(string[3]) 
qazzz) is not callable using argument types (string[3])
onlineapp.d(26):    cannot pass rvalue argument ["qwer", "ggg", 
"v"] of type string[3] to parameter ref const(string[3]) qazzz


WTF?


The ref. The problem is the ref. You are passing it a constant, not a 
variable.


Re: Local libraries/packages with dub: How?

2020-11-30 Thread rikki cattermole via Digitalmars-d-learn

On 01/12/2020 7:39 PM, z wrote:

On Tuesday, 1 December 2020 at 04:50:03 UTC, rikki cattermole wrote:

...


What puzzles me is that the dependencies are indeed declared, but "dub 
describe" refuses to recognize the dependencies and "dub build" fails.
"dub list" does recognize the root folder, but trying to get a 
subpackage to import another fails because the dependency isn't 
imported.(dmd only sees the "source" and phobos/runtime import paths)


The root dub.sdl roughly contains this :

name "fldr"
dependencies "fldr:spkg1" "fldr:spkg2" "fldr:spkg3" // tried with and 
without "fldr:"


That isn't right.

dependency "fldr:spkg1" version="*"
dependency "fldr:spkg2" version="*"
dependency "fldr:spkg3" version="*"


subPackage "./spkg1/"
subPackage "./spkg2/"
subPackage "./spkg3/"



targetType "none"


That probably isn't what you want. Either library or executable.
Either that, or you shouldn't be adding the dependencies.


While for example, "spkg3"'s dub.sdl contains this :

name "spkg3"
dependencies "fldr:spkg2"


dependency "fldr:spkg2" version="*"


  And its source/*.d file contains this :

import std.stdio, fldr.spkg2; //tried with and without "fldr."
void main() {writeln(«function from spkg2»)}


Don't forget to specify the module name. Every file should declare its 
module full package + module name.


So in this case ``module fldr.spkg2;``.


Re: Local libraries/packages with dub: How?

2020-11-30 Thread rikki cattermole via Digitalmars-d-learn
dub add-local, adds a directory as a known package that it can use as a 
dependency (or to be executed).


You need to specify in the package that depends on the dependency what 
dependencies you have.


I.e.

See the dependencies key:

{
"name": "myproject",
"description": "A little web service of mine.",
"authors": ["Peter Parker"],
"homepage": "http://myproject.example.com;,
"license": "GPL-2.0",
"dependencies": {
"vibe-d": "~>0.7.23"
}
}

See[0] how to specify the dependency itself.

To have different sets of dependencies/code you can use sub packages or 
configurations. But I would suggest to just focus on one set for now, 
while you are getting the hang of the basics.


[0] https://dub.pm/package-format-json#version-specs


Re: why is "hello".writeln considered bad?

2020-11-20 Thread rikki cattermole via Digitalmars-d-learn

I was the person who wrote that example.
It was just an example to show how it can be used.

I would not write a function call like that when using a literal.
As Mike said, its all up to personal preference.


Re: betterC question

2020-11-18 Thread rikki cattermole via Digitalmars-d-learn

On 19/11/2020 1:11 PM, Dibyendu Majumdar wrote:

On Thursday, 19 November 2020 at 00:08:59 UTC, Adam D. Ruppe wrote:

On Thursday, 19 November 2020 at 00:07:12 UTC, Dibyendu Majumdar wrote:

int function() fp = test;


This tries to *call* the function test and assign its return value to fp.



Really? why does it do that?


You don't need the brackets to call a function (and with a little help 
from UFCS):


void main() {
import std.stdio;

"Hello!".writeln;
writeln;
}


Re: toStringz lifetime

2020-11-08 Thread rikki cattermole via Digitalmars-d-learn

On 09/11/2020 2:58 PM, Ali Çehreli wrote:
Does the D GC know the complete function call stack of the C program all 
the way up from 'main'? Is there the concept of "bottom of the stack" or 
does the D GC can only know the value of the stack pointer at the time 
rt_init() was called. If the latter, then I think a toStringz string may 
not be alive in a C function.


https://github.com/dlang/druntime/blob/master/src/core/thread/context.d#L16
https://github.com/dlang/druntime/blob/master/src/core/thread/threadbase.d#L469
https://github.com/dlang/druntime/blob/master/src/core/thread/osthread.d#L1455
https://github.com/dlang/druntime/blob/master/src/core/thread/osthread.d#L1208

I'm tired, so here is the code related to your questions.

Note: the GC will use this abstraction for dealing with stack frames 
(otherwise it would be duplicated).


Re: Empty functions

2020-10-29 Thread rikki cattermole via Digitalmars-d-learn

On 29/10/2020 10:06 PM, Jan Hönig wrote:

On Thursday, 29 October 2020 at 09:01:12 UTC, Jan Hönig wrote:

This would mean, that this one should work as well.


It does not work as I intended, as `() => {}` has not the return type of 
`void`.


(I don't know how to print: `ReturnType!(() => {})`)


alias RT = void function();
alias Type = RT function();

() => 7;

is equivalent to:

int func() {
return 7;
}

Or:

() { return 7; }


Re: Empty functions

2020-10-29 Thread rikki cattermole via Digitalmars-d-learn

(Params){ FunctionBody; }

Rule: ref|opt ParameterWithMemberAttributes FunctionLiteralBody

https://dlang.org/spec/expression.html#function_literals




void function()

Is a type https://dlang.org/spec/type.html#delegates




() => {}

Is actually:

() => Expression

Rule: ref|opt ParameterWithMemberAttributes => AssignExpression

https://dlang.org/spec/expression.html#lambdas


Re: toStringz lifetime

2020-10-25 Thread rikki cattermole via Digitalmars-d-learn

On 25/10/2020 11:03 PM, Ali Çehreli wrote:
Does the GC see that local variable 'name' that is on the C side? What I 
don't know is whether the GC is aware only of the stack frames of D 
functions or the entire thread, which would include the C caller's 'name'.


The thread stack frame that is registered with the D GC will know about 
the D side and may know about the C side.


It depends on what the C side is doing.

If the C side went ahead and made a new stack frame via a fiber... it 
won't know about it. But even if it did, the D stack frame is still 
alive and pinning that bit of memory.


Ultimately, if the C side puts that pointer some place like a global or 
send it to another thread, there are no guarantees that things will play 
out well.


Re: GC-less string formatting

2020-10-20 Thread rikki cattermole via Digitalmars-d-learn

https://dlang.org/phobos/std_format.html#formattedWrite

Uses GC for exception (so cannot be @nogc yet), but otherwise it should 
be GC free.


Re: winapi, dll

2020-10-15 Thread rikki cattermole via Digitalmars-d-learn

On 16/10/2020 9:13 AM, Atmosfear wrote:


I'm a newby. Can you show me an example? In which module is it?


You can search for it on Github and it'll show up.

https://github.com/dlang/druntime/search?q=QueryPerformanceCounter


Re: Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.

2020-10-02 Thread rikki cattermole via Digitalmars-d-learn

On 02/10/2020 9:33 PM, Imperatorn wrote:

Did you create a D-partition just for D. Pro


You can mount directories as a drive on Windows.

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/subst


Re: dub sub-projects

2020-09-20 Thread rikki cattermole via Digitalmars-d-learn

On 21/09/2020 6:24 AM, Vladimirs Nordholm wrote:
I am unsure what the dub file would look like. I read that there is 
something called "subPackages", but in my mind I see them as 
dependencies. Is "subPackages" the right approach here?


Yes but no.

Normally all of these (what appear to be small but highly related code ) 
would go in the single repository which is when you would use subPackages.


But since you insist on them being separate repositories, then they are 
just regular old dependencies.


Re: Installing D on Fresh Windows 10 machine is a pain

2020-08-28 Thread rikki cattermole via Digitalmars-d-learn

On 28/08/2020 3:59 AM, Jesse Phillips wrote:


DMD installer still is unable to find "VS installed"


One of the reasons for this is that the environment variables have not 
been updated.


You need to restart to do this.


Re: Could someone calrify reserving and collecting memory via the Garbabe Collector ?

2020-08-06 Thread rikki cattermole via Digitalmars-d-learn

On 07/08/2020 5:12 AM, wjoe wrote:
There's core.memory.GC.reserve which requests memory from the OS. 
Basically pre-allocating memory for the GC heap.


Is the GC heap shared among all threads ?


That is up to the GC implementation.

And is it correct that even if I call GC.disable, the GC may still start 
a collection run if, for instance, there's an allocation but no free 
memory on the GC heap ?


"Disables automatic garbage collections performed to minimize the 
process footprint. Collections may continue to occur in instances where 
the implementation deems necessary for correct program behavior, such as 
during an out of memory condition. This function is reentrant, but 
enable must be called once for each call to disable."


https://dlang.org/phobos/core_memory.html#.GC.disable

So yes.

Note, out of memory is related to the process, rather than GC internals 
(it does play a part, but lets just go with process).


Re: Template error with gdc-10 but not with latest dmd and ldc

2020-07-26 Thread rikki cattermole via Digitalmars-d-learn

Old frontend:

Up to  2.060  : Failure with output: onlineapp.d(2): Error: valid 
attribute identifiers are @property, @safe, @trusted, @system, @disable 
not @nogc

2.061   to 2.065.0: Failure with output:
-
onlineapp.d(2): Error: user defined attributes cannot appear as postfixes
onlineapp.d(2): Error: semicolon expected following function declaration
onlineapp.d(2): Error: Declaration expected, not 'return'
onlineapp.d(2): Error: unrecognized declaration
-

2.066.0 to 2.078.1: Failure with output: onlineapp.d(7): Error: template 
instance add_long_n0!void does not match template declaration 
add_long_n0(alias T = void)(long x)
2.079.1 to 2.086.1: Failure with output: onlineapp.d(7): Error: template 
instance `add_long_n0!void` does not match template declaration 
`add_long_n0(alias T = void)(long x)`

Since  2.087.1: Success and no output


Re: Why is typeof(readln) -> void?

2020-07-18 Thread rikki cattermole via Digitalmars-d-learn

On 18/07/2020 9:14 PM, blizzard wrote:
Can anybody explain the difference between readln() and readln? I read 
somewhere that the () were optional, so why this difference?


The brackets are optional when calling a function. You are not calling a 
function if you wrap it in typeof.


"The Expression is not evaluated, it is used purely to generate the type:"

https://dlang.org/spec/declaration.html#Typeof


Re: Calling a C function whose name is a D reserved word or keyword

2020-07-06 Thread rikki cattermole via Digitalmars-d-learn

https://dlang.org/spec/pragma.html#mangle

pragma(mangle, "body")
extern(C) void body_func();


Re: Translating C headers to D: How do I compile it?

2020-06-27 Thread rikki cattermole via Digitalmars-d-learn

On 28/06/2020 4:59 PM, Kirill wrote:

module something;

extern(C)

int add(int a, int b);





Compile as static library some.c, add to command line of dmd.

Should be this simple more or less, depending on compilers and target 
involved.




Re: How to use base class & child class as parameter in one function ?

2020-05-22 Thread rikki cattermole via Digitalmars-d-learn

if (Child child = cast(Child)parent) {
assert(child !is null);
}


Re: any chance to get it working on windows xp?

2020-05-18 Thread rikki cattermole via Digitalmars-d-learn

On 19/05/2020 12:51 AM, a beginner wrote:

@rikki cattermole

Dmd and ldc's codegen haven't stood still for 10 years. They both will be
emitting instructions your cpu cannot handle. Hence crashes.
So... was I wrong to assume it generates code for the cpu it's running 
on (a P4 Northwood in my case) by default? I will try the "-mpcu" 
command line option then, and see if it takes care of that crash.


Yes.

Compilers make assumptions, especially dmd which uses newer instructions 
than an XP era build of dmd did.


But because D is self hosted, this means that the compiler itself has 
now been compiled with such instructions in use. So it too can crash.


Unless you bootstrap compile ldc up to the latest version (which also 
means LLVM), what options you pass it may very well not matter.


Re: any chance to get it working on windows xp?

2020-05-17 Thread rikki cattermole via Digitalmars-d-learn

It isn't just about the OS.

Dmd and ldc's codegen haven't stood still for 10 years. They both will 
be emitting instructions your cpu cannot handle. Hence crashes.


Re: Building Win32 application via dub

2020-04-29 Thread rikki cattermole via Digitalmars-d-learn

On 29/04/2020 10:27 PM, Sam E. wrote:
To be honest, I haven't yet found the way to switch between -m32 and 
-m64 (or other) via dub :)


$ dub build --arch=x86
$ dub build --arch=x86_64


Re: To get memory from another process.

2020-04-09 Thread rikki cattermole via Digitalmars-d-learn

On 10/04/2020 7:42 AM, Dennis wrote:

On Thursday, 9 April 2020 at 19:27:16 UTC, Quantium wrote:
I see this code imports drivers and does it depend on processor 
architecture? Would it work only on 64-bit or 32-bit or some special 
architechtures?


kernel32.dll and psapi.dll should be present on any normal Windows 10 
installation.


Windows only runs on x86 and ARM processors as far as I know. I have 
never used Windows with an ARM processor, but I assume such a Windows 
installation has the full WinAPI implemented, in which case it should work.


As for 32-bit/64-bit on x86:

- 32-bit OMF: might work, but I often get errors because the Digital 
Mars import libraries for Windows dll's are outdated so I don't 
recommend this target

- 32-bit COFF: pretty sure it works
- 64-bit COFF: definitely works, I use this regularly.

In any case, I suggest you just try these out to see yourself.


These API's are old and well used. They will work no problem on all targets.


Re: Dub will not load bindbc-harfbuzz

2020-04-09 Thread rikki cattermole via Digitalmars-d-learn

How old is your build of dub?

"betterC" build option was introduced in 1.20.0


Re: To get memory from another process.

2020-04-08 Thread rikki cattermole via Digitalmars-d-learn

On 09/04/2020 4:25 AM, Net wrote:

On Tuesday, 7 April 2020 at 21:20:28 UTC, Quantium wrote:
Could you advise me how to do these steps on D? Which libs should I 
import?

1. My programm gets a path to exe file
2. My programm starts that exe file and writes into it 2 commands
3. Programm gets access to exe file memory
4. Programm gets data from process memory and writes it into data.bin 
file which is in the same directory.
As I said, which libs do I need and how to get access to other process 
memory.

Also, can I make this as a driver, but if yes, how to code driver on D?


As far I know, you can't access other's program memory in any modern 
operating system.  That's managed and protected by the OS through 
virtual addressing.


Yes you can, in all modern operating systems.

It is used for debugging.



Re: Issues creating a dynamic libary with dub

2020-03-24 Thread rikki cattermole via Digitalmars-d-learn
When I see -fPIC I think something is wrong with your compiler+runtime 
setup.


Use -v to see the commands dub is using. This should not be dub related.


Re: can a unittest read main()'s args?

2020-03-22 Thread rikki cattermole via Digitalmars-d-learn

On 22/03/2020 8:57 PM, mark wrote:
I have a module with a unittest { ... } block. However, when I run dub 
test sometimes I want to output some extra data when the test runs. At 
the moment I control this by using an environment variable, but I 
wondered if it was possible to pass a command line argument 'dub test 
myarg' and if so how to access it?


dub run -- args

https://dlang.org/phobos/core_runtime.html#.Runtime.args


  1   2   3   4   5   6   7   8   9   10   >