Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
I have the following code: ``` import core.stdc.stdio; void print(T)(string prompt, T args...) { size_t len = prompt.length; size_t i = 0; while (prompt[i] != '{' && i < len) { printf("%c", prompt[i]); i++; } } void main() { print("Hello, world!\n", 10); } ``` When I execute

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread Mike Parker via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: When I execute it, I'm getting a range violation error. If I try to set "len" to be the length of the "prompt" minus 1, then it will work and it will print the "prompt" until the questionmark. So I cannot find where the error is... Beca

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread zjh via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: I have the following code: `prompt[i]!='{'`,here,i=len.so `array overflow`

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:38:50 UTC, Mike Parker wrote: On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: When I execute it, I'm getting a range violation error. If I try to set "len" to be the length of the "prompt" minus 1, then it will work and it will print the "prompt" until the

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:54:44 UTC, zjh wrote: On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: I have the following code: `prompt[i]!='{'`,here,i=len.so `array overflow` Thanks a lot. It seems I have a lot to learn. Have an amazing day!

Can I make system calls directly from D?

2021-07-09 Thread rempas via Digitalmars-d-learn
I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C

Re: Error: Outside Unicode code space

2021-07-09 Thread Tony via Digitalmars-d-learn
On Friday, 9 July 2021 at 03:32:31 UTC, Adam D Ruppe wrote: On Friday, 9 July 2021 at 03:09:52 UTC, Tony wrote: The editor I am using (Code::Blocks) displays the characters just fine. So it seems that the error message should be "Error: Outside the ASCII code space". D supports stuff outside

Re: Can I make system calls directly from D?

2021-07-09 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Friday, 9 July 2021 at 08:08:57 UTC, rempas wrote: I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C I don't know if it covers what you want but, druntime has those definitions: https://github.com/dlang/druntime/blob/master

Re: Can I make system calls directly from D?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 July 2021 at 08:08:57 UTC, rempas wrote: I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C If with directly means 'without calling any C function' you can use inline assembly: ```D version(linux) void rt_sigreturn(

Re: Can I make system calls directly from D?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 08:18:51 UTC, Ferhat Kurtulmuş wrote: On Friday, 9 July 2021 at 08:08:57 UTC, rempas wrote: I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C I don't know if it covers what you want but, druntime has th

Re: Can I make system calls directly from D?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 08:28:25 UTC, Dennis wrote: On Friday, 9 July 2021 at 08:08:57 UTC, rempas wrote: I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C If with directly means 'without calling any C function' you can use i

assign to property 2 values

2021-07-09 Thread Виталий Фадеев via Digitalmars-d-learn
I want this feature in D: ``` element.border = 1, solid; struct Element { @property void border( int width, BorderStyle style ) { this.borderWidth = width; this.borderStyle = style; } } ``` Description: ``` element.border = 1, solid; ``` will rewriten to the ``` element.border

Re: assign to property 2 values

2021-07-09 Thread Виталий Фадеев via Digitalmars-d-learn
On Friday, 9 July 2021 at 10:19:59 UTC, Виталий Фадеев wrote: I want this feature in D: ``` element.border = 1, solid; struct Element { @property void border( int width, BorderStyle style ) { this.borderWidth = width; this.borderStyle = style; } } ``` Description: ``` element.b

Re: assign to property 2 values

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 July 2021 at 10:19:59 UTC, Виталий Фадеев wrote: It possible in current version 2.097 ? If you `import std.typecons` you can do: ```D element.border = tuple(1, solid).expand; ``` But it's not pretty. I suggest either calling the function regularly, or combing all settings in a si

Re: assign to property 2 values

2021-07-09 Thread Виталий Фадеев via Digitalmars-d-learn
On Friday, 9 July 2021 at 11:04:23 UTC, Dennis wrote: On Friday, 9 July 2021 at 10:19:59 UTC, Виталий Фадеев wrote: It possible in current version 2.097 ? If you `import std.typecons` you can do: ```D element.border = tuple(1, solid).expand; ``` But it's not pretty. I suggest either calling t

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread Ali Çehreli via Digitalmars-d-learn
On 7/9/21 12:21 AM, rempas wrote: >while (prompt[i] != '{' && i < len) { In addition to what others said, you can take advantage of ranges to separate concerns of filtering and iteration. Here are two ways: import core.stdc.stdio; import std.algorithm; // Same as your original void print

Re: to compose or hack?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: But it got me thinking, how often do people roll their own vs. trying to compose using existing Phobos nuggets? When there's not an obvious/simple way to do something by composing ranges, I tend to just give up and write pr

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 11:56:40 UTC, Ali Çehreli wrote: In addition to what others said, you can take advantage of ranges to separate concerns of filtering and iteration. Here are two ways: [...] Of course another help from the legend himself ;) As always thanks a lot and have an amazing

Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read" etc. all exist. Anyone knows what's going

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rikki cattermole via Digitalmars-d-learn
On 10/07/2021 2:51 AM, rempas wrote: The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read"

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/21 10:51 AM, rempas wrote: The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read" etc.

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:04:32 UTC, rikki cattermole wrote: On 10/07/2021 2:51 AM, rempas wrote: The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open" func

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote: But reading/writing, closing these file descriptors is always the same. For sockets you'd typically use `recv` and `send` instead or `read` and `write` because the former give extra options and the latter don't work on Window

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote: On 7/9/21 10:51 AM, rempas wrote: The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open" func

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:31:50 UTC, Dennis wrote: On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote: But reading/writing, closing these file descriptors is always the same. For sockets you'd typically use `recv` and `send` instead or `read` and `write` because the former

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread Ali Çehreli via Digitalmars-d-learn
On 7/9/21 8:31 AM, rempas wrote: > I searched "fnctl" in the repo [...] Probably made a typo Yes, the typo should be obvious to the non-dyslexic among us. :) fnctl <-- wrong fcntl <-- correct Ali

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/21 11:31 AM, Dennis wrote: On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote: But reading/writing, closing these file descriptors is always the same. For sockets you'd typically use `recv` and `send` instead or `read` and `write` because the former give extra options a

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:37:41 UTC, Ali Çehreli wrote: On 7/9/21 8:31 AM, rempas wrote: > I searched "fnctl" in the repo [...] Probably made a typo Yes, the typo should be obvious to the non-dyslexic among us. :) fnctl <-- wrong fcntl <-- correct Ali Lol, I'm not dyslexic (or at least I

Re: Trivial simple OpenGl working example

2021-07-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 09, 2021 at 05:11:06AM +, Виталий Фадеев via Digitalmars-d-learn wrote: [...] > I using CPU Pentium B970 It is old CPU, but even it contains a > graphics accelerator. > Mesa DRI Intel(R) HD Graphics 2000 (SNB GT1), has 4 conveers on GPU. > Smartphones also contains GPU. > Because O

Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread rempas via Digitalmars-d-learn
I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in "hnsecs" and I cannot understand if we can change that and choose the precision. Does anyone know if we can do that?

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread Paul Backus via Digitalmars-d-learn
On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in "hnsecs" and I cannot understand if we can change that and choose the precision. Does anyone know

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread Ali Çehreli via Digitalmars-d-learn
On 7/9/21 1:54 PM, Paul Backus wrote: On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in "hnsecs" and I cannot understand if we can change that and c

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 20:54:21 UTC, Paul Backus wrote: On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in "hnsecs" and I cannot understand if we

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread jfondren via Digitalmars-d-learn
On Friday, 9 July 2021 at 21:13:02 UTC, rempas wrote: ``` Duration dur = end - start; dur = dur.total!"nsecs"; ``` What are you trying to do, assigning a nanosecond value to a Duration? The Duration already has that many nanoseconds in it. and I get the following error message: "Error: can

Re: assert(false) and GC

2021-07-09 Thread russhy via Digitalmars-d-learn
i think it only allocate when it hit the assert, but program will halt so it's not big deal, even though i feel this is a stupid design to make everything depend on GC... it gives bad impression when you want avoid it here is how i do to detect hidden GC allocations https://run.dlang.io/is/H

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 9 July 2021 at 21:13:02 UTC, rempas wrote: On Friday, 9 July 2021 at 20:54:21 UTC, Paul Backus wrote: On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the durati

Re: assert(false) and GC

2021-07-09 Thread Ali Çehreli via Digitalmars-d-learn
On 7/8/21 11:11 AM, DLearner wrote: Hi Please confirm that: `    assert(false, __FUNCTION__ ~ "This is an error message"); ` Will _not_ trigger GC issues, as the text is entirely known at compile time. Best regards One way of forcing compile-time evaluation in D is to define an enum (whi

Re: assert(false) and GC

2021-07-09 Thread russhy via Digitalmars-d-learn
On Friday, 9 July 2021 at 22:53:10 UTC, Ali Çehreli wrote: On 7/8/21 11:11 AM, DLearner wrote: Hi Please confirm that: `    assert(false, __FUNCTION__ ~ "This is an error message"); ` Will _not_ trigger GC issues, as the text is entirely known at compile time. Best regards One way of for

Re: assert(false) and GC

2021-07-09 Thread Ali Çehreli via Digitalmars-d-learn
On 7/9/21 4:12 PM, russhy wrote: >> One way of forcing compile-time evaluation in D is to define an enum >> (which means "manifest constant" in that use). That's all I meant. It was a general comment. > this is very bad, assert are good because they are one liner, making it > 2 line to avoid GC

Re: assert(false) and GC

2021-07-09 Thread russhy via Digitalmars-d-learn
On Friday, 9 July 2021 at 23:34:25 UTC, Ali Çehreli wrote: On 7/9/21 4:12 PM, russhy wrote: >> One way of forcing compile-time evaluation in D is to define an enum >> (which means "manifest constant" in that use). That's all I meant. It was a general comment. > this is very bad, assert are goo

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/21 5:04 PM, Ali Çehreli wrote: On 7/9/21 1:54 PM, Paul Backus wrote: On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in "hnsecs" and I cannot

Re: assert(false) and GC

2021-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/21 8:44 PM, russhy wrote: On Friday, 9 July 2021 at 23:34:25 UTC, Ali Çehreli wrote: On 7/9/21 4:12 PM, russhy wrote: >> One way of forcing compile-time evaluation in D is to define an enum >> (which means "manifest constant" in that use). That's all I meant. It was a general comment.

Re: assert(false) and GC

2021-07-09 Thread russhy via Digitalmars-d-learn
On Saturday, 10 July 2021 at 01:23:26 UTC, Steven Schveighoffer wrote: On 7/9/21 8:44 PM, russhy wrote: On Friday, 9 July 2021 at 23:34:25 UTC, Ali Çehreli wrote: On 7/9/21 4:12 PM, russhy wrote: >> One way of forcing compile-time evaluation in D is to >> define an enum >> (which means "mani

Re: Trivial simple OpenGl working example

2021-07-09 Thread Виталий Фадеев via Digitalmars-d-learn
On Friday, 9 July 2021 at 19:15:44 UTC, H. S. Teoh wrote: On Fri, Jul 09, 2021 at 05:11:06AM +, Виталий Фадеев via Digitalmars-d-learn wrote: [...] [...] [...] [...] Generally, text rendering on OpenGL is a huge pain to implement. This is not specific to D, but to OpenGL in general, be

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 21:04:42 UTC, Ali Çehreli wrote: On 7/9/21 1:54 PM, Paul Backus wrote: [...] Yes but the resolution seems not to be better than 100 nsecs. A quick research reveals a better resolution is not possible with common hardware on at least Linux. The following program al