Re: Using Postgres connection functions

2018-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 20 January 2018 at 04:09:01 UTC, Joe wrote: extern(C) char * [2] pvs; foreach (i, val; paramValues) pvs[i] = cast(char *)toStringz(val); And then use "cast(const char **)pvs" for the paramValues argument. A slight improvement here that removes the need for any casts

Re: Using Postgres connection functions

2018-01-19 Thread Joe via Digitalmars-d-learn
On Saturday, 13 January 2018 at 05:28:17 UTC, Joe wrote: Going beyond the connection, there are various other libpq functions that use a similar pattern of values passed using multiple parallel C arrays, e.g., PGresult *PQexecParams(PGconn *conn, const char *command,

Re: Local static variables must have unique names within a function's scope.

2018-01-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 19, 2018 10:11:36 H. S. Teoh via Digitalmars-d-learn wrote: > Fortunately this is not the case. However, the static variable case is > annoying, and it's actually one case of a larger problem: > > void main() { > foreach (i; 0 .. 10) { > struct S { >

Re: Cannot initialize associative array

2018-01-19 Thread rumbu via Digitalmars-d-learn
On Friday, 19 January 2018 at 23:27:06 UTC, Adam D. Ruppe wrote: On Friday, 19 January 2018 at 23:16:19 UTC, rumbu wrote: According to this (https://dlang.org/spec/hash-map.html#static_initialization) this is correct static initialization for AA: That only works inside a function, and,

Re: Cannot initialize associative array

2018-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 19 January 2018 at 23:16:19 UTC, rumbu wrote: According to this (https://dlang.org/spec/hash-map.html#static_initialization) this is correct static initialization for AA: That only works inside a function, and, ironically, only if the variable is not `static`... I believe this

Cannot initialize associative array

2018-01-19 Thread rumbu via Digitalmars-d-learn
According to this (https://dlang.org/spec/hash-map.html#static_initialization) this is correct static initialization for AA: immutable RoundingMode[string] ibmRounding = [ ">" : RoundingMode.towardPositive, "<" : RoundingMode.towardNegative, "0" : RoundingMode.towardZero,

Re: Program exiting from thread with infinite loop

2018-01-19 Thread Chris M. via Digitalmars-d-learn
On Friday, 19 January 2018 at 21:01:51 UTC, Steven Schveighoffer wrote: On 1/19/18 3:54 PM, Chris M. wrote: On Friday, 19 January 2018 at 20:43:18 UTC, Steven Schveighoffer wrote: On 1/19/18 12:05 PM, Chris M. wrote: [...] What is this call doing? You aren't importing std.stdio, so it

Re: Program exiting from thread with infinite loop

2018-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 01/19/2018 12:40 PM, Chris M. wrote: > it just runs the function once and exits every time. I would still put the following try+catch block around the whole logic: void deviceDownloader() { try { // ... existing contents of the function ... } catch (Exception exc) {

Re: Program exiting from thread with infinite loop

2018-01-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/19/18 3:54 PM, Chris M. wrote: On Friday, 19 January 2018 at 20:43:18 UTC, Steven Schveighoffer wrote: On 1/19/18 12:05 PM, Chris M. wrote: [...] What is this call doing? You aren't importing std.stdio, so it can't be D's normal write call. -Steve It is, left out the import on

Re: Program exiting from thread with infinite loop

2018-01-19 Thread Chris M. via Digitalmars-d-learn
On Friday, 19 January 2018 at 20:43:18 UTC, Steven Schveighoffer wrote: On 1/19/18 12:05 PM, Chris M. wrote: [...] What is this call doing? You aren't importing std.stdio, so it can't be D's normal write call. -Steve It is, left out the import on accident. I commented out the call to

Re: Program exiting from thread with infinite loop

2018-01-19 Thread Chris M. via Digitalmars-d-learn
On Friday, 19 January 2018 at 20:35:14 UTC, Chris M. wrote: On Friday, 19 January 2018 at 18:18:31 UTC, Ali Çehreli wrote: On 01/19/2018 09:46 AM, Chris M. wrote: > I tried putting an infinite loop inside main() as well, didn't seem to > help. Another reason is an exception thrown in the

Re: Program exiting from thread with infinite loop

2018-01-19 Thread Chris M. via Digitalmars-d-learn
On Friday, 19 January 2018 at 18:18:31 UTC, Ali Çehreli wrote: On 01/19/2018 09:46 AM, Chris M. wrote: > I tried putting an infinite loop inside main() as well, didn't seem to > help. Another reason is an exception thrown in the child thread. If the exception is not caught, it will terminate

Re: Local static variables must have unique names within a function's scope.

2018-01-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/19/18 1:11 PM, H. S. Teoh wrote: Fortunately this is not the case. However, the static variable case is annoying, and it's actually one case of a larger problem: void main() { foreach (i; 0 .. 10) { struct S {

Re: Local static variables must have unique names within a function's scope.

2018-01-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 19, 2018 at 02:16:24PM +, tipdbmp via Digitalmars-d-learn wrote: > > Mostly, it's just a bad idea - it's very easy for a person reading > > the code after you've written it to get the two x's mixed up. > > // example from: 19.17.1.3 > void main() > { > { static int x; } >

Re: Program exiting from thread with infinite loop

2018-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 01/19/2018 09:46 AM, Chris M. wrote: > I tried putting an infinite loop inside main() as well, didn't seem to > help. Another reason is an exception thrown in the child thread. If the exception is not caught, it will terminate the child thread and the main will not know anything about it.

Re: Program exiting from thread with infinite loop

2018-01-19 Thread Chris M. via Digitalmars-d-learn
On Friday, 19 January 2018 at 17:17:28 UTC, Adam D. Ruppe wrote: On Friday, 19 January 2018 at 17:05:44 UTC, Chris M. wrote: However when I try to spawn it in another thread it runs the function and then ends once it's done, like it's ignoring the while(true). It is probably terminating the

Re: Program exiting from thread with infinite loop

2018-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 19 January 2018 at 17:05:44 UTC, Chris M. wrote: However when I try to spawn it in another thread it runs the function and then ends once it's done, like it's ignoring the while(true). It is probably terminating the child threads when the main one ends. Might help to have the

Program exiting from thread with infinite loop

2018-01-19 Thread Chris M. via Digitalmars-d-learn
I have the following that is supposed to pull and store info from a server every five minutes. It works if I move the body of deviceDownloader into main(). However when I try to spawn it in another thread it runs the function and then ends once it's done, like it's ignoring the while(true). I

Re: Local static variables must have unique names within a function's scope.

2018-01-19 Thread tipdbmp via Digitalmars-d-learn
Mostly, it's just a bad idea - it's very easy for a person reading the code after you've written it to get the two x's mixed up. // example from: 19.17.1.3 void main() { { static int x; } { static int x; } // error { int i; } { int i; } // ok } I don't really see how the

Re: Local static variables must have unique names within a function's scope.

2018-01-19 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 19 January 2018 at 11:02:01 UTC, tipdbmp wrote: The following seems to work in C++, but errors in D, why is that? int foo(int* num) { { static int x = 10; x += 1; *num += x; } { static int x = 20; // error: foo.x is already defined in

Local static variables must have unique names within a function's scope.

2018-01-19 Thread tipdbmp via Digitalmars-d-learn
The following seems to work in C++, but errors in D, why is that? int foo(int* num) { { static int x = 10; x += 1; *num += x; } { static int x = 20; // error: foo.x is already defined in another scope in foo x += 2; *num += x; }