Re: Dynamically Sized Structs

2014-04-16 Thread monarch_dodra
On Thursday, 17 April 2014 at 00:55:19 UTC, Dicebot wrote: Just in case, the key line to pay attention to in that example is this one: CellIndex[0] c_; It is a commonly used C idiom for dynamically sized structures that D also supports. Absolutely. However, from a technical point of view, i

Re: Dynamically Sized Structs

2014-04-16 Thread Dicebot
On Wednesday, 16 April 2014 at 23:36:05 UTC, bearophile wrote: Jeroen Bollen: Is it possible to have a structure with a dynamic size? See an usage example I have written here: http://rosettacode.org/wiki/Sokoban#Faster_Version But that code requires a very updated compiler. Otherwise you wi

Re: Dynamically Sized Structs

2014-04-16 Thread Rene Zwanenburg
On Wednesday, 16 April 2014 at 23:15:43 UTC, Jeroen Bollen wrote: Is it possible to have a structure with a dynamic size? The structure would contain an array. I know I can use templates, but the size won't be known at compile time. I also know I could just put a dynamic array into it, but th

Re: Dynamically Sized Structs

2014-04-16 Thread bearophile
Jeroen Bollen: Is it possible to have a structure with a dynamic size? See an usage example I have written here: http://rosettacode.org/wiki/Sokoban#Faster_Version But that code requires a very updated compiler. Otherwise you will need a little different code. Bye, bearophile

Re: Dynamically Sized Structs

2014-04-16 Thread Justin Whear
On Wed, 16 Apr 2014 23:15:40 +, Jeroen Bollen wrote: > Is it possible to have a structure with a dynamic size? The structure > would contain an array. > > I know I can use templates, but the size won't be known at compile time. > I also know I could just put a dynamic array into it, but that

Re: Understanding switch + foreach

2014-04-16 Thread Matej Nanut
Well, I'm still confused by this. I also noticed that the compiler doesn't complain if I omit the break statements in the generated switch, but complains normally if I write it out like so: ``` switch (key) { case 1: "Found 1!".writefln(); break; case 2: "Fo

Dynamically Sized Structs

2014-04-16 Thread Jeroen Bollen
Is it possible to have a structure with a dynamic size? The structure would contain an array. I know I can use templates, but the size won't be known at compile time. I also know I could just put a dynamic array into it, but that way it would just be a pointer. I know there would be major is

Re: What's the current phobos way to define generic data sources and sinks?

2014-04-16 Thread David Nadlinger
On Wednesday, 16 April 2014 at 21:05:30 UTC, Hannes Steffenhagen wrote: I've looked at std.stream, but it says in big red scary letters that I probably shouldn't be using it. Is there a suitable replacement? If not, I'd just roll my own and provide a couple of templates to automatically generat

What's the current phobos way to define generic data sources and sinks?

2014-04-16 Thread Hannes Steffenhagen
I've looked at std.stream, but it says in big red scary letters that I probably shouldn't be using it. Is there a suitable replacement? If not, I'd just roll my own and provide a couple of templates to automatically generate wrappers for them.

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread Capture_A_Lag
Thanks everyone for figuring everything out!

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread FreeSlave
It also throws if you input initial or trailing spaces and there are no spaces at the start or end of format string (scanf skips these spaces)

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread FreeSlave
On Wednesday, 16 April 2014 at 18:46:18 UTC, Ali Çehreli wrote: On 04/16/2014 11:36 AM, FreeSlave wrote: Note that readf is not equivalent to scanf since readf does not skip spaces and newline character. Input must completely match format. Just like in scanf, a single space character is suffi

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread Ali Çehreli
On 04/16/2014 11:36 AM, FreeSlave wrote: Note that readf is not equivalent to scanf since readf does not skip spaces and newline character. Input must completely match format. Just like in scanf, a single space character is sufficient to consume zero or more whitespace characters. Ali

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread FreeSlave
Note that readf is not equivalent to scanf since readf does not skip spaces and newline character. Input must completely match format.

Re: ref & address

2014-04-16 Thread Chris
On Wednesday, 16 April 2014 at 17:20:52 UTC, Adam D. Ruppe wrote: OK, you could also store a pointer to the InputRange as your member. With structs, assignment is making a private copy, so if you want to update the original in a stored thing you'll need the pointer. ref doesn't work with anyt

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread Justin Whear
On Wed, 16 Apr 2014 18:17:37 +, Capture_A_Lag wrote: > Thank you everybody!!! > I thought %d is ok for all integral types. This is true when using the D format functions (e.g. readf) which are able to inspect the types of the variables being assigned, but scanf is a C function and not types

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread Capture_A_Lag
Thank you everybody!!! I thought %d is ok for all integral types.

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread FreeSlave
On Wednesday, 16 April 2014 at 17:47:05 UTC, Capture_A_Lag wrote: Hi all! I have this code: -- ubyte N, M, K; ubyte[][max][max] Matrix; scanf("%d %d %d", &N, &M, &K); ubyte tmp; for(ubyte n = 1; n <= N; n++) f

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread Dicebot
On Wednesday, 16 April 2014 at 17:47:05 UTC, Capture_A_Lag wrote: Hi all! I have this code: -- ubyte N, M, K; ubyte[][max][max] Matrix; scanf("%d %d %d", &N, &M, &K); ubyte tmp; for(ubyte n = 1; n <= N; n++) f

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread Ali Çehreli
On 04/16/2014 10:47 AM, Capture_A_Lag wrote: > ubyte tmp; > scanf("%d", &tmp); > // After this scanf n becomes 0 for no reason %d is for int. Ali P.S. A friendly request: It makes it much easier for the rest of the group if posts contained compilable, minimal but co

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread Justin Whear
On Wed, 16 Apr 2014 17:47:03 +, Capture_A_Lag wrote: > Hi all! > I have this code: > > -- > ubyte N, M, K; > ubyte[][max][max] Matrix; > > scanf("%d %d %d", &N, &M, &K); > > ubyte tmp; > > for(ubyte n = 1; n <= N;

Re: Scanf function changes value of in-loop variable

2014-04-16 Thread bearophile
Capture_A_Lag: After scanf in loop variable n becomes 0. Is this a bug? Please help me! Have you tried to use a tmp of type int to avoid stomping? Bye, bearophile

Scanf function changes value of in-loop variable

2014-04-16 Thread Capture_A_Lag
Hi all! I have this code: -- ubyte N, M, K; ubyte[][max][max] Matrix; scanf("%d %d %d", &N, &M, &K); ubyte tmp; for(ubyte n = 1; n <= N; n++) for(ubyte m = 1; m <= M; m++) { scanf("%d",

Re: ref & address

2014-04-16 Thread Adam D. Ruppe
OK, you could also store a pointer to the InputRange as your member. With structs, assignment is making a private copy, so if you want to update the original in a stored thing you'll need the pointer. ref doesn't work with anything other than function arguments in D.

Re: ref & address

2014-04-16 Thread Chris
On Wednesday, 16 April 2014 at 16:21:42 UTC, Adam D. Ruppe wrote: What's the definition of InputRange? Is it the interface from std.range? If so, don't pass it as ref. interfaces are references to the object by default. In general, you only need ref when you want to assign a new object to t

Re: ref & address

2014-04-16 Thread Adam D. Ruppe
What's the definition of InputRange? Is it the interface from std.range? If so, don't pass it as ref. interfaces are references to the object by default. In general, you only need ref when you want to assign a new object to the variable and want that change to be seen outside the function t

ref & address

2014-04-16 Thread Chris
The following: this(ref InputRange r) { writeln(&r); this.r = r; writeln(&this.r); } 7FFF2BD74D50 // r 7FFF2BD745F0 // this.r Why? And how can I change this?

std.file.read returns void[] why?

2014-04-16 Thread Spacen Jasset
Why does the read function return void[] and not byte[] void[] read(in char[] name, size_t upTo = size_t.max);

Re: Implicit conversions through purity

2014-04-16 Thread Jonathan M Davis
On Tuesday, April 15, 2014 18:01:59 bearophile wrote: > Steve Teale: > > Since this is D-Learn, I can be indignant, and say that D needs > > to get its act together, and have a clean definition of 'pure'. > > What you describe is not only undocumented, but also far too > > complicated - pure weak n