On Saturday, 23 March 2024 at 21:59:57 UTC, Nick Treleaven wrote:
On Saturday, 23 March 2024 at 21:53:43 UTC, Jonathan M Davis
wrote:
Yes, it's a bug. It's a clear violation of the type system if
a non-mutable variable is ever given a value more than once.
It should be initialized, and then it
On Saturday, 23 March 2024 at 21:53:43 UTC, Jonathan M Davis
wrote:
Yes, it's a bug. It's a clear violation of the type system if a
non-mutable variable is ever given a value more than once. It
should be initialized, and then it should be treated as illegal
to ever assign to it - or to do
On Saturday, March 23, 2024 3:23:23 PM MDT Nick Treleaven via Digitalmars-d-
learn wrote:
> I've not used static constructors before, but it seems like the
> following should not be allowed:
>
> ```d
> import std.stdio;
>
> immutable int x;
>
> @safe shared static this()
> {
> x.writeln(); //
I've not used static constructors before, but it seems like the
following should not be allowed:
```d
import std.stdio;
immutable int x;
@safe shared static this()
{
x.writeln(); // 0
x = 5;
x.writeln(); // 5
x = 6;
x++;
assert(x == 7);
}
```
Should I file a bug to
The mutex isn't more "global", it's more "local" (although,
this will make it shared).
Yes shared, this is what I meant by global :) Thanks, it's
clearer now.
On 1/17/21 6:54 PM, ludo wrote:
Yes alright. I think the dev made a design mistake because he called
synchronized( OpenAL.mutex ) when it should be more of a global, non
OpenAL specific, mutex. I mean in the code there were things like
(pseudo-code)
---
System {
private int[] buffer
Thanks, as explained I am indeed porting old code.
No on the AA (as noted above). The mutex *is* created on
demand. Every Object can have a mutex, and it's only created
when you synchronize it for the first time.
Yes alright. I think the dev made a design mistake because he
called
On 1/6/21 12:05 PM, ludo wrote:
I read in the documentation
"Static constructors are used to initialize static class members with
values that cannot be computed at compile time"
I try to understand the design of the following code:
---
class OpenAL
{
static string[int] ALErrorLookup;
r the late reply.
No worry and thank you. I found the low-lock pattern on my own,
digging more info. Smart pattern!
I put the synchronized function in front of the function. The
problem with multithreading, is the difficulty to verify that
it works fine :) But now the topic streams away f
e low-lock pattern on my own,
digging more info. Smart pattern!
I put the synchronized function in front of the function. The
problem with multithreading, is the difficulty to verify that it
works fine :) But now the topic streams away from static
constructor :) Cheers
On Tuesday, 12 January 2021 at 11:28:12 UTC, ludo wrote:
Ok, I agree that ends up being a kind of strange singleton. But
yes it was D v1 code. Do we agree that the following
multi-threaded singleton pattern is the proper way as of today.
It looks fine to me. The D wiki has the following
)();
}
}
return instance;
}
---
As for some of the other stuff, Associative Array literals in D
can't actually be used at compile-time (at least, last time I
tried), so they have to be created inside of the static
constructor.
OK, I found
https://dlang.org/spec/hash-map.html
On Thursday, 7 January 2021 at 01:55:07 UTC, SealabJaster wrote:
...
And on a side note, I don't believe this code is working as the
author intends.
Someone correct me if I'm wrong, but `static` variables in D
arethread-local, so a `static Object mutex` wouldn't actually be
visible
, Associative Array literals in D
can't actually be used at compile-time (at least, last time I
tried), so they have to be created inside of the static
constructor.
Next is the mutex. `Object` is the base class that every class in
D will implicitly inherit from, like in C# for example. Object
On Wednesday, 6 January 2021 at 17:05:02 UTC, ludo wrote:
I read in the documentation
"Static constructors are used to initialize static class
members with values that cannot be computed at compile time"
[...]
Since this is not the complete code it's a bit hard to know, but
I'd guess this
I read in the documentation
"Static constructors are used to initialize static class members
with values that cannot be computed at compile time"
I try to understand the design of the following code:
---
class OpenAL
{
static string[int] ALErrorLookup;
static Object mutex;
On Thursday, 8 August 2019 at 16:04:33 UTC, a11e99z wrote:
On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov
wrote:
I have the following code:
// main.d
int main()
{
import std.stdio;
writeln("hello");
return 0;
}
But if I create library from lib.d first and then link it
On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote:
But if I create library from lib.d first and then link it with
main.d then ctor/dtor are not called:
For this to work as expected, the `lib.obj` object file needs to
be linked into the final executable. As main.d doesn't need
On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote:
I have the following code:
// main.d
int main()
{
import std.stdio;
writeln("hello");
return 0;
}
But if I create library from lib.d first and then link it with
main.d then ctor/dtor are not called:
$ dmd.exe -lib
On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote:
I have the following code:
// lib1/lib.d
module lib;
import std.stdio;
static this()
{
writeln("+" ~ __FILE__);
}
static ~this()
{
writeln("-" ~ __FILE__);
}
// main.d
int main()
{
import std.stdio;
I have the following code:
// lib1/lib.d
module lib;
import std.stdio;
static this()
{
writeln("+" ~ __FILE__);
}
static ~this()
{
writeln("-" ~ __FILE__);
}
// main.d
int main()
{
import std.stdio;
writeln("hello");
return 0;
}
So if I compile lib.d and main.d together
On Saturday, 23 March 2019 at 16:56:28 UTC, tchaloupka wrote:
On Saturday, 23 March 2019 at 15:58:07 UTC, Sobaya wrote:
What I am saying is that it can not be read when a code
importing (a.d) a code including the static constructor (b.d)
is compiled into shared library.
Hi. I've tried
On Saturday, 23 March 2019 at 15:58:07 UTC, Sobaya wrote:
What I am saying is that it can not be read when a code
importing (a.d) a code including the static constructor (b.d)
is compiled into shared library.
Hi. I've tried to add your case to the repository and at it seems
to be working
the environment variable LD_LIBRARY_PATH.
I do not know what is the correct way on linux.
Kind regards
Andre
This is not a problem of path, I think.
Because when I do not write static constructor in b.d, that
code works.
This problem occurs only when static constructor is used.
Did you noticed
is the correct way on linux.
Kind regards
Andre
This is not a problem of path, I think.
Because when I do not write static constructor in b.d, that
code works.
This problem occurs only when static constructor is used.
Did you noticed this thread?
https://forum.dlang.org/post/eumnxgxtjrvvkhxpw
This is not a problem of path, I think.
Because when I do not write static constructor in b.d, that code
works.
This problem occurs only when static constructor is used.
On Friday, 22 March 2019 at 10:51:58 UTC, Sobaya wrote:
I fail to load the shared library created in a specific
situation, but I do not know the cause.
a.d
import b.d
b.d
static this() {}
for above 2 files, I created shared library by following
command.
dmd a.d -shared
I fail to load the shared library created in a specific
situation, but I do not know the cause.
a.d
import b.d
b.d
static this() {}
for above 2 files, I created shared library by following command.
dmd a.d -shared -of=a.so
And I ran below code, but the library is not
maintest.d:
http://pastebin.com/3c4CKDG1
Compiled with DMD 2.050:
dmd maintest.d maintest.def
The output in the log file is Lenght: 0. The static constructor is
never called when using WinMain.
But if I use a normal void main() function instead of WinMain, then
the static constructor does get
. The static constructor is
never called when using WinMain.
But if I use a normal void main() function instead of WinMain, then
the static constructor does get called. Here's a working example that
tests a GUI dialogbox and outputs Length: 4 in the log file:
maintest.def:
EXETYPE NT
SUBSYSTEM
Andrej Mitrovic n...@none.none wrote:
maintest.def:
EXETYPE NT
SUBSYSTEM WINDOWS
maintest.d:
http://pastebin.com/3c4CKDG1
Compiled with DMD 2.050:
dmd maintest.d maintest.def
The output in the log file is Lenght: 0. The static constructor is
never called when using WinMain.
But if I use
On Tue, 23 Nov 2010 15:23:12 -0500, Andrej Mitrovic wrote:
The static constructor is never called when using WinMain.
Make sure you use newest DMD, I think in 2.048 or 49 there was bug that
module constructors were not called.
32 matches
Mail list logo