C structs

2014-06-20 Thread Johann Lermer via Digitalmars-d-learn
Hi, I'm fiddling around with cairo (downloaded fromhttps://github.com/D-Programming-Deimos/cairo) and I stumbled over this problem: (file rectandmatrix.d) import deimos.cairo.cairo; void main () { cairo_rectangle_int_t rect; cairo_matrix_t matrix; } Compiling that with

Re: C structs

2014-06-20 Thread Johann Lermer via Digitalmars-d-learn
Agreed, but I assumed, that since all definitions in cairo.d are defined as extern (System), (same happens with extern (C), btw.), I would have expected, that D does not implicitly generate initialisation functions. So, why is there no init routine for the rectangle? There's only one for the

Re: Distinguish float and integer types from string

2019-03-11 Thread Johann Lermer via Digitalmars-d-learn
On Saturday, 9 March 2019 at 18:11:09 UTC, Jacob Shtokolov wrote: I tried to use std.conv.to and std.conv.parse, but found that they can't really do this. When I call `data.to!int`, the value of "123.45" will be converted to int! Are you sure? This here works for me: import std.stdio; import

Re: const pointers C vs. D

2020-02-06 Thread Johann Lermer via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 10:17:39 UTC, Dennis wrote: C++ has a const system that is closer to D's than any other language, but it still has huge differences: Thanks, that clears it up a bit!

const pointers C vs. D

2020-02-04 Thread Johann Lermer via Digitalmars-d-learn
Hi, I'm just wondering about defining const pointers and if there's a difference in C and D. in C, this works: const char* text = "Hello"; text = "world"; but in D it doesn't, because the char* is const. Ff I would like tho have the same behaviour in D as in C, I need to write: const

Re: sending the address of a struct

2020-09-06 Thread Johann Lermer via Digitalmars-d-learn
On Sunday, 6 September 2020 at 11:10:14 UTC, Simen Kjærås wrote: auto e = receiveOnly!(shared(Env)*); Oh, thanks. Seems, that I just missed that bit with the pranetheses.

sending the address of a struct

2020-09-06 Thread Johann Lermer via Digitalmars-d-learn
Hi, I have a struct in a separate thread and want to pass it's address back to the main thread. This is how I think it should work: import std.concurrency; struct Env {} void run () { shared Env env; ownerTid.send (); for (;;) {} } void main () { spawn ();

Re: How Stop Worker Thread if Owner Thread is Finished?

2020-10-27 Thread Johann Lermer via Digitalmars-d-learn
You could tell your thread via a shared variable that main has ended: import std.stdio; import std.concurrency; import core.thread; shared bool end = false; void thread () { for (;;) { Thread.sleep (500.msecs); synchronized {

Re: How to implement Canceleable spawn() from parent

2020-06-29 Thread Johann Lermer via Digitalmars-d-learn
I'm doing this in an X11 application in order to send a timer event every 100 milliseconds to the main event queue. class Application { shared private bool s_tick; void clock_task (shared X11.Display* disp, X11.Atom atom, X11.Window win) { for (;;) { try {

Re: Visual D showing weird errors

2021-04-26 Thread Johann Lermer via Digitalmars-d-learn
On Monday, 26 April 2021 at 08:58:25 UTC, Raimondo Mancino wrote: According to -v: DMD64 D Compiler v2.096.0-dirty Well, that says it all, doesn't it? I'm not familiar with the windows versions, but that doesn't seem to be an offical release - at least I never had a dmd2 that claimed to be

Re: Visual D showing weird errors

2021-04-26 Thread Johann Lermer via Digitalmars-d-learn
On Monday, 26 April 2021 at 10:42:54 UTC, Mike Parker wrote: (According to -v: DMD64 D Compiler v2.096.0-dirty) That's actually normal for the Windows versions. I'm not sure where it comes from, but it's always there. Ouuu, that's bad advertising, isn't it? Who wants to use dirty software, it

alias this - am I using it wrong?

2021-08-25 Thread Johann Lermer via Digitalmars-d-learn
Hi all, I have a little problem understanding alias this. I always thought, that alias this only makes implicit conversions from the aliased object to this. Then, why do lines 18 and 22 compile in the code below? And, btw, line 22 crashes with a segmentation fault. ```d 01 struct

Re: alias this - am I using it wrong?

2021-08-25 Thread Johann Lermer via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 12:23:06 UTC, Adam D Ruppe wrote: ... Thanks - that explains in all. On Wednesday, 25 August 2021 at 12:23:32 UTC, FeepingCreature wrote: class Alias_Class { Test_Struct ts; Test_Struct getter() { return ts; } alias getter this; } Good idea,

problem with alias this and Tuple

2021-10-12 Thread Johann Lermer via Digitalmars-d-learn
Hi all, I have a problem with Tuples and struct templates that contain an alias this: ```d import std; struct Element(T) { T payload; alias payload this; this (T p) { payload = p; } } class Item {} void main () { auto e =

Re: problem with alias this and Tuple

2021-10-12 Thread Johann Lermer via Digitalmars-d-learn
Thanks, understood. But isn't this a deficiency in the library that should be fixed?