Re: Problem with Exceptions in Constructor

2021-06-11 Thread Mike Parker via Digitalmars-d-learn

On Friday, 11 June 2021 at 20:09:22 UTC, Mike Brown wrote:



The error is flagged on the writeln(e.msg). Do I need to do 
something special to pass a string to an exception? dup?




No, that code is fine. You're passing a string literal, so 
there's no need for a dup.


Re: Unittests not firing?

2021-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 11, 2021 at 02:05:31PM -0700, H. S. Teoh wrote:
[...]
> Huh, that doesn't look right. This was fixed since June last year, so it
> *should* have made it into the latest compiler releases already. Unless
> this one was missed somehow (but I doubt it).
[...]

Just checked on LDC 1.26.0, the message has already been fixed.  I
seriously doubt the beta would have the fix reverted somehow; this seems
to be a sign that your druntime is indeed out-of-sync with your
compiler.  You should check your system for stray stale copies of
druntime.


T

-- 
Caffeine underflow. Brain dumped.


Re: Unittests not firing?

2021-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 11, 2021 at 08:30:28PM +, Mike Brown via Digitalmars-d-learn 
wrote:
> On Friday, 11 June 2021 at 16:28:48 UTC, H. S. Teoh wrote:
> > On Fri, Jun 11, 2021 at 03:20:49PM +, Mike Brown via
> > Digitalmars-d-learn wrote:
> > > On Friday, 11 June 2021 at 15:13:17 UTC, rikki cattermole wrote:
> > [...]
> > > Right OK, mine says 1/1 unittests failed - but this should say
> > > Modules?
> > > 
> > > I will interpret it as Modules, ty!
> > 
> > This is a bug that was fixed in more recent versions of druntime.
> > Basically it was a misleading message because the count is the
> > number of modules, not the number of individual tests.
[...]
> OK, thank you - Im using LDC 1.27.0-beta1 which looks to be the newest
> I can find, is there a way to update the druntime manually?

Huh, that doesn't look right. This was fixed since June last year, so it
*should* have made it into the latest compiler releases already. Unless
this one was missed somehow (but I doubt it).


> I've problems with exceptions that might be related to me being out of
> date?
[...]

Are you sure your druntime is up-to-date with your LDC version?  One
thing to beware of is stale copies of druntime lying around that the
compiler picked up instead of the latest version.  This may lead to
subtle discrepancies that cause strange runtime problems like runtime
crashes or other odd behaviours.  (Though generally this shouldn't be a
problem with LDC, it's more commonly a problem with DMD installations.)


T

-- 
If the comments and the code disagree, it's likely that *both* are wrong. -- 
Christopher


Re: Unittests not firing?

2021-06-11 Thread Mike Brown via Digitalmars-d-learn

On Friday, 11 June 2021 at 16:28:48 UTC, H. S. Teoh wrote:
On Fri, Jun 11, 2021 at 03:20:49PM +, Mike Brown via 
Digitalmars-d-learn wrote:
On Friday, 11 June 2021 at 15:13:17 UTC, rikki cattermole 
wrote:

[...]
Right OK, mine says 1/1 unittests failed - but this should say 
Modules?


I will interpret it as Modules, ty!


This is a bug that was fixed in more recent versions of 
druntime. Basically it was a misleading message because the 
count is the number of modules, not the number of individual 
tests.



T


Hi T,

OK, thank you - Im using LDC 1.27.0-beta1 which looks to be the 
newest I can find, is there a way to update the druntime manually?


I've problems with exceptions that might be related to me being 
out of date?


Kind regards,
Mike Brown


Problem with Exceptions in Constructor

2021-06-11 Thread Mike Brown via Digitalmars-d-learn

Hi all,

AddressSanitizer is throwing an access-violation error - I've 
managed to boil it down to this example:


```d
import std.stdio;

class example: Exception {
	this(string msg, string file = __FILE__, size_t line = __LINE__) 
{

super(msg, file, line);
}
}

class test {
this() {
throw new example("this is a test");
}
}

void main() {
try {
auto t = new test();
} catch (example e) {
writeln(e.msg);
}
}
```

Compiled with:
ldc2.exe -g -fsanitize='address' .\test.d -of='test.exe'

The error is flagged on the writeln(e.msg). Do I need to do 
something special to pass a string to an exception? dup?


Kind regards,
Mike Brown


Re: Two interpretations

2021-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 11, 2021 at 03:00:00PM +, JG via Digitalmars-d-learn wrote:
> Is it specified somewhere which way the following program will be
> interpreted?
> 
> import std;
> 
> struct A
> {
> int x=17;
> }
> 
> int x(A a)
> {
> return 100*a.x;
> }
> 
> void main()
> {
> A a;
>writeln(a.x);
> }

The rule is that member functions will always take precedence over UFCS.
UFCS only kicks in when the member function of that name cannot be
found.


T

-- 
For every argument for something, there is always an equal and opposite 
argument against it. Debates don't give answers, only wounded or inflated egos.


Re: Unittests not firing?

2021-06-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 11, 2021 at 03:20:49PM +, Mike Brown via Digitalmars-d-learn 
wrote:
> On Friday, 11 June 2021 at 15:13:17 UTC, rikki cattermole wrote:
[...]
> Right OK, mine says 1/1 unittests failed - but this should say
> Modules?
> 
> I will interpret it as Modules, ty!

This is a bug that was fixed in more recent versions of druntime.
Basically it was a misleading message because the count is the number of
modules, not the number of individual tests.


T

-- 
Дерево держится корнями, а человек - друзьями.


Re: Unittests not firing?

2021-06-11 Thread Mike Brown via Digitalmars-d-learn

On Friday, 11 June 2021 at 15:13:17 UTC, rikki cattermole wrote:


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.


Right OK, mine says 1/1 unittests failed - but this should say 
Modules?


I will interpret it as Modules, ty!


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.


Two interpretations

2021-06-11 Thread JG via Digitalmars-d-learn
Is it specified somewhere which way the following program will be 
interpreted?


import std;

struct A
{
int x=17;
}

int x(A a)
{
return 100*a.x;
}

void main()
{
A a;
   writeln(a.x);
}


Unittests not firing?

2021-06-11 Thread Mike Brown via Digitalmars-d-learn

Hi all,

I'm testing the unittest features of D, and having some issues. I 
only seem able to fire one unittest, e.g.


module test;

unittest {
assert(0);
}

unittest {
assert(0);
}

If I run,
rdmd -g -unittest -main "test.d"

It returns,
1/1 unittests FAILED
test.d(4): [unittest] unittest failure

Im using rdmd as I want a simple command that will pull in 
dependancies to run these tests. Am I right in using rdmd?


I have also tried ldc2 and getting the same results. What am I 
missing?


Kind regards,
Mike Brown


Creating a static library

2021-06-11 Thread Mike Brown via Digitalmars-d-learn

Hi all,

My goal is to modularise my code better.

I think I'd like to make a static library, this will primarily to 
be used in other D projects.


https://dlang.org/articles/dll-linux.html mentions the GC and 
linking requirements. I am happy to not use the GC for this 
library, what is the best way to turn this off for the entire 
library?


I would like to be able to select a library at link time, 
libraries with the same interface but different implemenations - 
to build different versions of my project (e.g. Windows, Linux 
etc).

It would be useful to understand how in D the best way to this?

Is there a good tutorial or information on the above?

Kind regards,
Mike


Re: difficulty with rectangular arrays

2021-06-11 Thread Dennis via Digitalmars-d-learn

On Friday, 11 June 2021 at 08:30:29 UTC, Moth wrote:

what's going on?


It's a bug:
[Issue 19178 - Static initialization of 2d static arrays in 
structs produces garbage or doesn't compile 
sometimes](https://issues.dlang.org/show_bug.cgi?id=19178)





Re: difficulty with rectangular arrays

2021-06-11 Thread Moth via Digitalmars-d-learn

On Friday, 11 June 2021 at 08:40:51 UTC, jfondren wrote:


The example in the spec is in a function body and you've copied
it to a class body, where the writeln() would also be in error.
I find https://dlang.org/spec/grammar.html quite hard to read
but I imagine there's a state/declaration distinction there, 
despite

the code looking the same.

This works:

```d
class Example {
double[6][3] matrix;
this() {
matrix = 0;
}
}
```


i see.
that's a bummer - i knew the `writeln()` wouldn't work in a class 
body, but i assumed that because other initializations work [e.g, 
`int myint = 4;` or `int[69] funny = 420;`], this case would be 
much the same. ah well.


off topic, your baba is you avatar is very cute.


Re: difficulty with rectangular arrays

2021-06-11 Thread jfondren via Digitalmars-d-learn

On Friday, 11 June 2021 at 08:30:29 UTC, Moth wrote:

```
class ExampleClass
{
double[6][3] matrix = 0; //fails to compile - "Error: 
cannot implicitly convert expression `0` of type `int` to 
`double[6][3]`"

}
```

evidently i'm doing something wrong here, but i can't 
understand what or why. what's going on? have i misread the 
spec?


The example in the spec is in a function body and you've copied
it to a class body, where the writeln() would also be in error.
I find https://dlang.org/spec/grammar.html quite hard to read
but I imagine there's a state/declaration distinction there, 
despite

the code looking the same.

This works:

```d
class Example {
double[6][3] matrix;
this() {
matrix = 0;
}
}
```



Re: Cast class reference to pointer of another class?

2021-06-11 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 10 June 2021 at 23:47:33 UTC, Paul Backus wrote:

On Thursday, 10 June 2021 at 21:25:35 UTC, JN wrote:
I have to disagree. I don't see a good reason for this 
behavior and it's just one more thing to trip people. I think 
it'd be better if such thing was done explicit, something like:


```d
Bar b = new Bar();
Foo* f2 = cast(Foo*)b.ptr;
```


Isn't having to write out `cast(Foo*)` already pretty explicit?


^


difficulty with rectangular arrays

2021-06-11 Thread Moth via Digitalmars-d-learn

hullo all. i've encountered a bizzare inconsistency.

the following is the [D spec on rectangular 
arrays](https://dlang.org/spec/arrays.html#rectangular-arrays):


```
void main()
{
import std.stdio: write, writeln, writef, writefln;
double[6][3] matrix = 0; // Sets all elements to 0.
writeln(matrix); // [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], 
[0, 0, 0, 0, 0, 0]]

}
```


however, when i attempt to place the very same code within a 
class...


```
class ExampleClass
{
double[6][3] matrix = 0; //fails to compile - "Error: cannot 
implicitly convert expression `0` of type `int` to `double[6][3]`"

}
```

evidently i'm doing something wrong here, but i can't understand 
what or why. what's going on? have i misread the spec?




Re: Flaoting point operations : unexpected results

2021-06-11 Thread frame via Digitalmars-d-learn

On Thursday, 10 June 2021 at 20:18:03 UTC, seany wrote:

On Thursday, 10 June 2021 at 19:51:51 UTC, Dennis wrote:

On Thursday, 10 June 2021 at 19:37:36 UTC, seany wrote:
However, i sometimes see, that the results are _radically_ 
different.


Are you using uninitialized memory or multi-threading?


I am using things like :

`double [][] myArr = new double [][] (0,0);`



I dont think these are "uninitialized"?


Just to clarify, this statement does not initialize double values 
to 0. It just creates the array with lengths of 0. If you disable 
range checking as in release mode, you wouldn't see any error 
here.