Re: Wrong result with enum

2021-11-11 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 11 November 2021 at 14:52:45 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: Unless explicitly set, default type is int. 110 is greater than int.max. 11 ```d enum w = 100_000; size_t b = w * w; // size_t b =

Re: Completing C code with D style

2021-11-11 Thread forkit via Digitalmars-d-learn
On Thursday, 11 November 2021 at 19:34:42 UTC, Stanislav Blinov wrote: Original C code from the first post can only fail on I/O, which is arguably out of your control. And the meat of it amounts to 10 conditional stores. Your implementations, in both C and D, are a very, very far distance

Re: Completing C code with D style

2021-11-11 Thread forkit via Digitalmars-d-learn
On Friday, 12 November 2021 at 01:05:15 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 22:10:04 UTC, forkit wrote: It's called 'staged learning'. Staged learning is the only way for humans to learn, due to the limitations of the human cognitive system. Specifically, the way

Re: Completing C code with D style

2021-11-11 Thread foxit via Digitalmars-d-learn
On Friday, 12 November 2021 at 01:05:15 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 22:10:04 UTC, forkit wrote: It's called 'staged learning'. Staged learning is the only way for humans to learn, due to the limitations of the human cognitive system. Specifically, the way

Re: Completing C code with D style

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 22:10:04 UTC, forkit wrote: It's called 'staged learning'. Staged learning is the only way for humans to learn, due to the limitations of the human cognitive system. Specifically, the way short-term memory and long-term memory facilitate learning. Those who

Re: Completing C code with D style

2021-11-11 Thread foxit via Digitalmars-d-learn
On Thursday, 11 November 2021 at 23:41:48 UTC, kdevel wrote: On Thursday, 11 November 2021 at 22:30:12 UTC, forkit wrote: [...] for(int i = 0; i < sizeof(numbers) / sizeof(int); ++i) // is so much safer - in C style I made it even safer: for (int i = 0; i < sizeof numbers / sizeof

Re: Completing C code with D style

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 21:56:19 UTC, Ali Çehreli wrote: On 11/11/21 11:34 AM, Stanislav Blinov wrote: > Pessimization, though, is laughably easy, and > should be avoided at all costs. I am not passionate about this topic at all and I am here mostly because I have fun in this forum.

Re: Is DMD still not inlining "inline asm"?

2021-11-11 Thread Elronnd via Digitalmars-d-learn
On Thursday, 11 November 2021 at 13:22:15 UTC, Basile B. wrote: As for now, I know no compiler that can do that. GCC can do it. Somewhat notoriously, LTO can lead to bugs from underspecified asm constraints following cross-TU inlining.

Re: How to use dmd code coverage

2021-11-11 Thread foxit via Digitalmars-d-learn
On Thursday, 11 November 2021 at 22:35:21 UTC, forkit wrote: On Thursday, 11 November 2021 at 21:40:33 UTC, Ali Çehreli wrote: On 11/11/21 1:37 PM, forkit wrote: dmd test.d -cov ...but no .lst file anywhere to be found. Huh! I don't get it. Please run the program! :) Ali oh! that kinda

Re: Completing C code with D style

2021-11-11 Thread kdevel via Digitalmars-d-learn
On Thursday, 11 November 2021 at 22:30:12 UTC, forkit wrote: [...] for(int i = 0; i < sizeof(numbers) / sizeof(int); ++i) // is so much safer - in C style I made it even safer: for (int i = 0; i < sizeof numbers / sizeof *numbers; ++i) Maybe the type of numbers is changed in the

Re: How to use dmd code coverage

2021-11-11 Thread forkit via Digitalmars-d-learn
On Thursday, 11 November 2021 at 21:40:33 UTC, Ali Çehreli wrote: On 11/11/21 1:37 PM, forkit wrote: dmd test.d -cov ...but no .lst file anywhere to be found. Huh! I don't get it. Please run the program! :) Ali oh! that kinda makes sense, now that I think of it ;-)

Re: Completing C code with D style

2021-11-11 Thread forkit via Digitalmars-d-learn
On Tuesday, 2 November 2021 at 23:45:39 UTC, pascal111 wrote: Next code originally was a classic C code I've written, it's pure vertical thinking, now, I converted it successfully to D code, but I think I made no much changes to make it has more horizontal thinking style that it seems D

Re: Completing C code with D style

2021-11-11 Thread forkit via Digitalmars-d-learn
On Thursday, 11 November 2021 at 21:13:03 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote: It depends on what you're doing. In the OP's example, yeah worrying about allocations is totally blowing things out of proportions. But that's the thing.

Re: Completing C code with D style

2021-11-11 Thread Ali Çehreli via Digitalmars-d-learn
On 11/11/21 11:34 AM, Stanislav Blinov wrote: > Pessimization, though, is laughably easy, and > should be avoided at all costs. I am not passionate about this topic at all and I am here mostly because I have fun in this forum. So, I am fine in general. However, I don't agree that

Re: How to use dmd code coverage

2021-11-11 Thread Ali Çehreli via Digitalmars-d-learn
On 11/11/21 1:37 PM, forkit wrote: dmd test.d -cov ...but no .lst file anywhere to be found. Huh! I don't get it. Please run the program! :) Ali

How to use dmd code coverage

2021-11-11 Thread forkit via Digitalmars-d-learn
// -- module test; import std.stdio; void main() { writeln("Hello World!"); } // --- dmd test.d -cov ..but no .lst file anywhere to be found. Huh! I don't get it.

Re: Completing C code with D style

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote: It depends on what you're doing. In the OP's example, yeah worrying about allocations is totally blowing things out of proportions. But that's the thing. How would one ever learn to know where that dividing line is if all the

Re: Completing C code with D style

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 10 November 2021 at 23:15:09 UTC, forkit wrote: On Wednesday, 10 November 2021 at 22:17:48 UTC, russhy wrote: On Wednesday, 10 November 2021 at 06:47:32 UTC, forkit wrote: btw. My pc has 24GB of main memory, and my CPU 8MB L3 cache. So I really don't give a damn about allocations

Re: Is DMD still not inlining "inline asm"?

2021-11-11 Thread max haughton via Digitalmars-d-learn
On Thursday, 11 November 2021 at 17:29:33 UTC, rempas wrote: On Thursday, 11 November 2021 at 13:22:15 UTC, Basile B. wrote: Yes, this is still the case. A particularity of DMD inliner is that it does its job in the front-end, so inlining asm is totally impossible. Then, even if inlining was

Re: Is DMD still not inlining "inline asm"?

2021-11-11 Thread rempas via Digitalmars-d-learn
On Thursday, 11 November 2021 at 13:22:15 UTC, Basile B. wrote: Yes, this is still the case. A particularity of DMD inliner is that it does its job in the front-end, so inlining asm is totally impossible. Then, even if inlining was done in the backend inlining of asm would not be guaranteed

Re: Is DMD still not inlining "inline asm"?

2021-11-11 Thread rempas via Digitalmars-d-learn
On Thursday, 11 November 2021 at 12:05:14 UTC, Adam D Ruppe wrote: You really shouldn't expect dmd to inline *anything*. Or to optimize anything for that matter. That isn't its strength. Oh yeah! I just thought to ask anyway! Thanks a lot for your time!

Re: Completing C code with D style

2021-11-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 11, 2021 at 01:09:26AM +, forkit via Digitalmars-d-learn wrote: > On Thursday, 11 November 2021 at 00:11:07 UTC, H. S. Teoh wrote: > > On Wed, Nov 10, 2021 at 11:39:40PM +, forkit via Digitalmars-d-learn > > wrote: [...] > > > I still remember compiling code on my 286x86 ...

Re: Wrong result with enum

2021-11-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: Unless explicitly set, default type is int. 110 is greater than int.max. 11 ```d enum w = 100_000; size_t b = w * w; // size_t b = 10 * 10; // ??? assert(b == 10_000_000_000); // Assert Failure ```

Re: Is DMD still not inlining "inline asm"?

2021-11-11 Thread Basile B. via Digitalmars-d-learn
On Thursday, 11 November 2021 at 08:58:43 UTC, rempas wrote: I've seen from [this](https://forum.dlang.org/post/op.vrzngqeavxi10f@biotronic-laptop) reply in a thread from 2011 that DMD will not inline functions that contain inline assembly. Is this still the case? Yes, this is still the case.

Re: Wrong result with enum

2021-11-11 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result void main() { size_t subTest1 = tLimit; assert(subTest1 == tLimit);/* no error */

Re: Wrong result with enum

2021-11-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result That's an `int` literal. Try enum wLimit = 100_000L; the L suffix makes a `long` literal.

Re: Wrong result with enum

2021-11-11 Thread Patrick Schluter via Digitalmars-d-learn
On Thursday, 11 November 2021 at 12:05:19 UTC, Tejas wrote: On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: On Thursday, 11 November 2021 at 06:34:16 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need

Re: Wrong result with enum

2021-11-11 Thread Tejas via Digitalmars-d-learn
On Thursday, 11 November 2021 at 09:11:37 UTC, Salih Dincer wrote: On Thursday, 11 November 2021 at 06:34:16 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result

Re: Is DMD still not inlining "inline asm"?

2021-11-11 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 11 November 2021 at 08:58:43 UTC, rempas wrote: I've seen from [this](https://forum.dlang.org/post/op.vrzngqeavxi10f@biotronic-laptop) reply in a thread from 2011 that DMD will not inline functions that contain inline assembly. Is this still the case? You really shouldn't expect

Re: Wrong result with enum

2021-11-11 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 11 November 2021 at 06:34:16 UTC, Stanislav Blinov wrote: On Thursday, 11 November 2021 at 05:37:05 UTC, Salih Dincer wrote: is this a issue, do you need to case? ```d enum tLimit = 10_000; // (1) true result enum wLimit = 100_000; // (2) wrong result ```

Is DMD still not inlining "inline asm"?

2021-11-11 Thread rempas via Digitalmars-d-learn
I've seen from [this](https://forum.dlang.org/post/op.vrzngqeavxi10f@biotronic-laptop) reply in a thread from 2011 that DMD will not inline functions that contain inline assembly. Is this still the case?