Text UI for D

2013-03-24 Thread DLearner
Can anyone recommend a simple text UI (something like Newt) which can be used from within a D program?

GDC - no flush to stdio?

2013-04-01 Thread DLearner
I was trying to use writef("Escape string" ~ "Display string") to simulate a full-screen console. But writef doesn't seem to flush until a newline entered (which disturbs cursor position). I would have expected a 'flush()' function, but 'flush()' itself produces an error (does not exist), and

Re: GDC - no flush to stdio?

2013-04-01 Thread DLearner
On Monday, 1 April 2013 at 18:44:16 UTC, Ali Çehreli wrote: On 04/01/2013 11:37 AM, DLearner wrote: I was trying to use writef("Escape string" ~ "Display string") to simulate a full-screen console. But writef doesn't seem to flush until a newline entered (which dist

Re: GDC - no flush to stdio?

2013-04-01 Thread DLearner
On Monday, 1 April 2013 at 19:01:07 UTC, H. S. Teoh wrote: On Mon, Apr 01, 2013 at 08:53:40PM +0200, DLearner wrote: On Monday, 1 April 2013 at 18:44:16 UTC, Ali Çehreli wrote: >On 04/01/2013 11:37 AM, DLearner wrote: >>I was trying to use writef("Escape string" ~ &quo

Re: GDC - no flush to stdio?

2013-04-02 Thread DLearner
On Monday, 1 April 2013 at 20:32:25 UTC, Johannes Pfau wrote: Am Mon, 01 Apr 2013 13:26:53 -0700 schrieb Ali Çehreli : On 04/01/2013 01:06 PM, DLearner wrote:> On Monday, 1 April 2013 at 19:01:07 UTC > I tried your example, getting four error messages first of which > was &

Raw keyboard input

2013-08-16 Thread DLearner
Hi, Please, under Debian / GDC, what functions are available to read keys directly as pressed (no wait for )? And how used (infinite loop exited on specific keycode, eg for 'Esc')?

Re: good reasons not to use D?

2015-11-03 Thread DLearner via Digitalmars-d-learn
+ 2.2 = 3.3003 Agreed. Suggest 'dec' type. Example: dec foo{15,3}; Means simple variable 'foo' can hold fifteen digits, last three decimal places. DLearner

Where does one post a proposal for a language change?

2016-07-12 Thread DLearner via Digitalmars-d-learn
General/Issues/or...

Assert question

2016-07-26 Thread DLearner via Digitalmars-d-learn
Suppose a program contains several points that control should not get to. So each such point is blocked by assert(0). What is the recommended way of identifying which assert has been triggered? Is one allowed anything like 'assert(0,"Crashed at point A");', where the message goes to stderr?

Callbacks in D

2016-10-06 Thread DLearner via Digitalmars-d-learn
Please, could someone post here, or provide a link to, some simple, debugged examples. Best regards

DLang/Wiki/'Hello World'/Run Code/Disassembly

2016-10-21 Thread DLearner via Digitalmars-d-learn
Code ran with expected output, but Disassembly seemed to go in a loop?

Re: DLang/Wiki/'Hello World'/Run Code/Disassembly

2016-10-21 Thread DLearner via Digitalmars-d-learn
On Friday, 21 October 2016 at 09:07:35 UTC, cym13 wrote: On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote: [...] What makes you think that? It's hard to tell if you don't give any information. I pressed the 'Run' button and got the 'Hello World

Loading assimp

2017-01-09 Thread Dlearner via Digitalmars-d-learn
I'm trying to use assimp to load models in a program. I see the Derelict binding is for version 3.3, but the assimp site has no binaries for this, just source. So I try to use version 3.1.1 and I get this error: derelict.util.exception.SymbolLoadException@..\..\AppData\Roaming\dub\packages\d

Re: Loading assimp

2017-01-10 Thread Dlearner via Digitalmars-d-learn
On Tuesday, 10 January 2017 at 00:10:12 UTC, Mike Parker wrote: On Monday, 9 January 2017 at 18:13:03 UTC, Dlearner wrote: I'm trying to use assimp to load models in a program. I see the Derelict binding is for version 3.3, but the assimp site has no binaries for this, just source. So

Changing template parameters

2017-01-16 Thread Dlearner via Digitalmars-d-learn
Hey, quick question! I'm messing around with std.random and noticed that you can change the boundaries parameter to be either open or closed intervals on either side. By default it is "[)". How do I change these template parameters?

Re: Changing template parameters

2017-01-16 Thread Dlearner via Digitalmars-d-learn
On Monday, 16 January 2017 at 16:08:07 UTC, Rene Zwanenburg wrote: On Monday, 16 January 2017 at 15:56:16 UTC, Jack Stouffer wrote: Same way you use any template parameters, auto i = uniform!("(]")(0, 1000); Also, if the template parameter consists of a single token you can omit the par

Making .exe

2017-01-19 Thread Dlearner via Digitalmars-d-learn
Hey! I wrote a little program that has an image bounce around and change colours, like the old DVD player screensavers. How can I build this as a little .exe file that I can send to someone? In the dub documentation there is something like `dub --build=`, but I'm not entirely sure what this

Re: Making .exe

2017-01-19 Thread Dlearner via Digitalmars-d-learn
On Thursday, 19 January 2017 at 20:56:41 UTC, Nemanja Boric wrote: On Thursday, 19 January 2017 at 18:58:31 UTC, Dlearner wrote: [...] Hello! The binary should be in the working directory: ``` ➜ dub init Package recipe format (sdl/json) [json]: Name [test-dub]: Description [A minimal D

Learning resources

2017-01-24 Thread Dlearner via Digitalmars-d-learn
Hey all! I'm learning programming through D and having a really good time (much better than with C++ or Python). I'm aiming to make little games with it as a hobby so I've learned some OpenGL stuff. But, I feel like I'm learning more library code rather than D concepts and idioms, especially

Re: Learning resources

2017-01-24 Thread Dlearner via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 21:14:08 UTC, pineapple wrote: On Tuesday, 24 January 2017 at 20:15:38 UTC, Dlearner wrote: Hey all! I'm learning programming through D and having a really good time (much better than with C++ or Python). I'm aiming to make little games with it as

Re: Learning resources

2017-01-25 Thread Dlearner via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 22:53:14 UTC, bachmeier wrote: On Tuesday, 24 January 2017 at 20:15:38 UTC, Dlearner wrote: [...] This sounds like exactly what you want: https://www.packtpub.com/application-development/d-cookbook It's not on sale right now, but if you've got the m

Re: Loading assimp

2017-01-29 Thread Dlearner via Digitalmars-d-learn
Need to rez this thread because I ran into a wall. Two little things: 1) Can't seem to get the Importer class to work ("undefined identifier 'Importer' ", etc), and 2) GetTexture and GetTextureCount for aiMaterial don't seem to work (source\model.d(105,28): Error: no property 'GetTextureCount

Re: Loading assimp

2017-03-26 Thread Dlearner via Digitalmars-d-learn
I came back to this project and realised my mistakes (Importer is a class for the C++ API, and we're using the C API). So I fixed all my errors, but now I get an access violation. As far as I can tell, it seems to be an issue with `aiGetMaterialTexture`. It is meant to return an aiString with a

Re: Loading assimp

2017-03-26 Thread Dlearner via Digitalmars-d-learn
On Sunday, 26 March 2017 at 11:10:55 UTC, ag0aep6g wrote: On Sunday, 26 March 2017 at 10:34:21 UTC, Dlearner wrote: I came back to this project and realised my mistakes (Importer is a class for the C++ API, and we're using the C API). So I fixed all my errors, but now I get an access viol

Re: Loading assimp

2017-03-26 Thread Dlearner via Digitalmars-d-learn
On Sunday, 26 March 2017 at 12:40:42 UTC, Dlearner wrote: ... About half the textures seem to load fine. Some progress! I don't know why, but when I get to the 8th texture, the filename has some garbage attached. SDL_Surface* surface = IMG_Load(filename.ptr); if (surface is

Re: Loading assimp

2017-03-27 Thread Dlearner via Digitalmars-d-learn
On Sunday, 26 March 2017 at 21:52:42 UTC, ag0aep6g wrote: On 03/26/2017 11:31 PM, Dlearner wrote: SDL_Surface* surface = IMG_Load(filename.ptr); if (surface is null) { writeln("surface is null: ", to!string(IMG_GetError())); } else { writeln(filename);

Re: Importing modules under DUB on Windows

2022-10-26 Thread DLearner via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 16:58:08 UTC, H. S. Teoh wrote: On Wed, Oct 26, 2022 at 04:20:01PM +, DLearner via Digitalmars-d-learn wrote: Hi Never used DUB before. Wanted to use a function stored in a module outside the main source. Main source has `import ;` Put a line into the

Re: Importing modules under DUB on Windows

2022-10-26 Thread DLearner via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 18:53:58 UTC, Hipreme wrote: On Wednesday, 26 October 2022 at 18:37:00 UTC, DLearner wrote: On Wednesday, 26 October 2022 at 16:58:08 UTC, H. S. Teoh wrote: On Wed, Oct 26, 2022 at 04:20:01PM +, DLearner via Digitalmars-d-learn wrote: [...] Maybe try

Re: Importing modules under DUB on Windows

2022-10-27 Thread DLearner via Digitalmars-d-learn
On Thursday, 27 October 2022 at 00:35:26 UTC, Hipreme wrote: On Wednesday, 26 October 2022 at 22:51:53 UTC, DLearner wrote: On Wednesday, 26 October 2022 at 18:53:58 UTC, Hipreme wrote: On Wednesday, 26 October 2022 at 18:37:00 UTC, DLearner wrote: [...] The linker failed to resolve because

Re: Importing modules under DUB on Windows

2022-10-28 Thread DLearner via Digitalmars-d-learn
On Friday, 28 October 2022 at 11:35:44 UTC, Adam D Ruppe wrote: On Wednesday, 26 October 2022 at 16:20:01 UTC, DLearner wrote: Wanted to use a function stored in a module outside the main source. easiest thing to do with dub is to add it as a sourcePath or a sourceFile. Well, actually

Re: Importing modules under DUB on Windows

2022-10-28 Thread DLearner via Digitalmars-d-learn
On Friday, 28 October 2022 at 21:32:46 UTC, rikki cattermole wrote: On 29/10/2022 4:15 AM, DLearner wrote: However, going forward, I don't want copies of OM anywhere other than UD. If you want your own private library on your system (that will get used a lot), you can create a packag

Comparison of two 'dynamic arrays'.

2022-11-13 Thread DLearner via Digitalmars-d-learn
Hi Program has two steps: 1. Creates an array (int[] A), whose size and element values are only known at run-time. Then: 2. The elements (but not the array size) are further processed in a way that may or may not alter their value. Requirement: to identify the indices (if any) of the elemen

Re: Comparison of two 'dynamic arrays'.

2022-11-13 Thread DLearner via Digitalmars-d-learn
On Sunday, 13 November 2022 at 14:39:26 UTC, Siarhei Siamashka wrote: On Sunday, 13 November 2022 at 14:28:45 UTC, DLearner wrote: Creating a step 1.5: ``` int[] B = A; ``` ```D auto B = A.dup; ``` This will create a copy of A rather than referencing to the same buffer in memory. Tested

Re: Comparison of two 'dynamic arrays'.

2022-11-13 Thread DLearner via Digitalmars-d-learn
On Sunday, 13 November 2022 at 16:11:17 UTC, matheus. wrote: [...] You should add the code below after "auto B = A.dup;": B[0].Txt = A[0].Txt.dup; The "Txt" property inside B is still referencing A without the above. Matheus. Thank you - your suggestion worked. The slight generalisati

Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread DLearner via Digitalmars-d-learn
To me, it appears that there are really two (_entirely separate_) concepts: A. Supporting the useful concept of variable length (but otherwise entirely conventional) arrays; B. Supporting a language feature that acts as a window to an array, through which that array can be manipulated. And c

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread DLearner via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 19:06:20 UTC, rikki cattermole wrote: [...] Please see the following example: ``` void main() { import std.stdio; int[] VarArr1, VarArr2; VarArr1.length = 6; VarArr1[5] = 10; VarArr1[4] = 9; VarArr1[3] = 8; VarArr1[2] = 7; VarArr1[1] = 6

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-12-03 Thread DLearner via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 02:29:03 UTC, Paul Backus wrote: [...] If you want a dynamic array with value semantics, you should use a library-defined container type (e.g., `struct DynamicArray`). I agree should not change existing meaning of ``` int[] A; ``` But why not allow a const

GC interaction with malloc/free

2023-01-05 Thread DLearner via Digitalmars-d-learn
Suppose there is a D main program (not marked anywhere with @nogc), that _both_ A: Calls one or more C functions that themselves call malloc/free; and also B: Calls one or more D functions that themselves call malloc/free via `import core.stdc.stdlib;` Assuming the malloc/free's are used cor

Re: GC interaction with malloc/free

2023-01-05 Thread DLearner via Digitalmars-d-learn
On Thursday, 5 January 2023 at 19:54:01 UTC, H. S. Teoh wrote: On Thu, Jan 05, 2023 at 07:49:38PM +, DLearner via Digitalmars-d-learn wrote: Suppose there is a D main program (not marked anywhere with @nogc), that _both_ A: Calls one or more C functions that themselves call malloc/free

BetterC unexpected results

2023-01-08 Thread DLearner via Digitalmars-d-learn
I thought dynamic arrays were unavailable under -betterC. Example_02: ``` extern(C) void main() { import core.stdc.stdio : printf; int[] A; printf("Hello betterC\n"); } ``` ``` dmd -betterC -run Example_02 ``` Expected result: Failure at compilation stage, owing to presence of dynamic

Re: BetterC unexpected results

2023-01-11 Thread DLearner via Digitalmars-d-learn
On Sunday, 8 January 2023 at 23:59:21 UTC, ryuukk_ wrote: [...] Example_03: ``` void main() { import core.stdc.stdio : printf; int[] A; printf("Hello betterC\n"); } ``` ``` dmd -betterC -run Example_03 ``` Expected result: Failure at compilation stage, owing to presence of dynamic arr

Unittests on a module

2023-01-13 Thread DLearner via Digitalmars-d-learn
If unittest run without a main() being present, crashes on link error: ``` lld-link: error: subsystem must be defined Error: linker exited with status 1 ``` Is this intended? It's not a problem to add temporary ``` void main() { } ``` to the bottom of the module, but seems wrong as not then te

Problem with ImportC example?

2023-01-17 Thread DLearner via Digitalmars-d-learn
This relates to the first example under 41.1 Quick Examples. Stored as ex01.c, run as shown. ``` #include int main() { printf("hello world\n"); return 0; } ``` Produced: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is no

Re: Problem with ImportC example?

2023-01-17 Thread DLearner via Digitalmars-d-learn
On Tuesday, 17 January 2023 at 11:21:08 UTC, Dennis wrote: On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is not supported ex01.c(1): Error: no type for declara

Re: Problem with ImportC example?

2023-01-17 Thread DLearner via Digitalmars-d-learn
On Tuesday, 17 January 2023 at 15:55:40 UTC, bachmeier wrote: On Tuesday, 17 January 2023 at 13:21:37 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 11:21:08 UTC, Dennis wrote: On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>

Re: Problem with ImportC example?

2023-01-17 Thread DLearner via Digitalmars-d-learn
On Tuesday, 17 January 2023 at 17:36:41 UTC, ryuukk_ wrote: On Tuesday, 17 January 2023 at 17:12:49 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 15:55:40 UTC, bachmeier wrote: On Tuesday, 17 January 2023 at 13:21:37 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 11:21:08 UTC

Re: Problem with ImportC example?

2023-01-17 Thread DLearner via Digitalmars-d-learn
On Tuesday, 17 January 2023 at 19:17:31 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 17:36:41 UTC, ryuukk_ wrote: On Tuesday, 17 January 2023 at 17:12:49 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 15:55:40 UTC, bachmeier wrote: [...] Downloaded latest dmd for windows from

Re: Problem with ImportC example?

2023-01-18 Thread DLearner via Digitalmars-d-learn
On Tuesday, 17 January 2023 at 22:11:46 UTC, Ali Çehreli wrote: [...] dmd relies on system compiler programs for its ImportC feature. cl.exe seems to be the compiler. I think it is the compiler. Can you run that program from the command line? Fails with: ``` C:\Users\SoftDev>c1.exe 'c1.exe'

Re: Problem with ImportC example?

2023-01-18 Thread DLearner via Digitalmars-d-learn
On Wednesday, 18 January 2023 at 14:18:58 UTC, Salih Dincer wrote: On Wednesday, 18 January 2023 at 13:45:04 UTC, DLearner wrote: On Tuesday, 17 January 2023 at 22:11:46 UTC, Ali Çehreli wrote: [...] dmd relies on system compiler programs for its ImportC feature. cl.exe seems to be the

foreach with assoc. array

2023-03-01 Thread DLearner via Digitalmars-d-learn
Hi Please consider (1): ``` void main() { import std.stdio; int wk_Idx; int[2] IntArr; IntArr[0] = 1; IntArr[1] = 2; for (wk_Idx = 0; wk_Idx <= 1; wk_Idx = wk_Idx + 1) { writeln("wk_Idx = ", wk_Idx, " IntArr = ", IntArr[wk_Idx]); } } ``` Now consider (2), which is

'auto' keyword

2023-03-12 Thread DLearner via Digitalmars-d-learn
Is it correct that this _single_ keyword is used to indicate _two_ quite different things: 1. As a shorthand to make the type of the variable being declared the same as the type on the right hand side of an initial assignment. Example: ```auto A = 5;``` makes A an int. 2. To indicate storag

Variable length arrays under -betterC?

2023-04-17 Thread DLearner via Digitalmars-d-learn
Requirement is to write some D code (which avoids the GC), that will be called from C. So simple approach seemed to be to write D code under -betterC restrictions. However, also need variable length arrays - but D Dynamic Arrays not allowed under -betterC. So tried trivial example using std.c

Linking external functions?

2023-04-18 Thread DLearner via Digitalmars-d-learn
Wanted to try out linking two source files independantly compiled. ExtCallee.d source file: ``` extern(C) void ExtCallee() { import std.stdio; writeln("Entered: ", __FUNCTION__); writeln("Exiting: ", __FUNCTION__); } ``` ExtMain.d source file: ``` void main() { import std.stdio; e

Re: Linking external functions?

2023-04-18 Thread DLearner via Digitalmars-d-learn
On Tuesday, 18 April 2023 at 20:00:18 UTC, ag0aep6g wrote: On Tuesday, 18 April 2023 at 19:49:04 UTC, DLearner wrote: ``` void main() { import std.stdio; extern(C) void ExtCallee(); ``` Move that declaration out of main. Thanks - worked! Is the declaration inside main not visible to

Re: Linking external functions?

2023-04-18 Thread DLearner via Digitalmars-d-learn
On Tuesday, 18 April 2023 at 21:31:21 UTC, thinkunix wrote: [...] If not calling C code, why use extern(C) for D code? Wanted to test out options of calling D routine (possibly -betterC) from both C and (full) D.

ImportC issue?

2023-04-19 Thread DLearner via Digitalmars-d-learn
C source ex01.c: ``` #include int main() { printf("hello world\n"); return 0; } ``` 'dmc ex01.c' produces message: ``` link ex01,,,user32+kernel32/noi; ``` but does generate .obj, .map and .exe files, and the exe executes properly. However, trying to use ImportC via 'dmd ex01.c' produces

Re: ImportC issue?

2023-04-19 Thread DLearner via Digitalmars-d-learn
On Wednesday, 19 April 2023 at 11:50:28 UTC, bachmeier wrote: [...] Did you use the switch `-m32omf`? https://dlang.org/spec/importc.html#auto-cpp No so following the references I tried every preprocessor option I could find: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c -m32omf f

Re: ImportC issue?

2023-04-19 Thread DLearner via Digitalmars-d-learn
On Wednesday, 19 April 2023 at 12:09:44 UTC, Richard (Rikki) Andrew Cattermole wrote: On 20/04/2023 12:07 AM, DLearner wrote: Error: C preprocess command sppn.exe failed for file ex01.c, exit status 1 Did you verify that sppn is accessible in that shell? As in run it, can it be found? If

Re: ImportC issue?

2023-04-19 Thread DLearner via Digitalmars-d-learn
On Wednesday, 19 April 2023 at 14:42:44 UTC, bachmeier wrote: [...] My understanding (from my occasional use of Windows) is that DMD installs the Community Edition of Visual Studio. That should solve your original issue, and you shouldn't need to mess with sppn.exe. Well it took a little whil

D style - member functions

2023-04-26 Thread DLearner via Digitalmars-d-learn
Consider: ``` struct S1 { int A; int B; int foo() { return(A+B); } } struct S2 { int A; int B; } int fnAddS2(S2 X) { return (X.A + X.B); } void main() { import std.stdio : writeln; S1 Var1 = S1(1, 2); writeln("Total Var1 = ", Var1.foo()); S2 Var2 = S2(1,

unittest under betterC

2023-06-04 Thread DLearner via Digitalmars-d-learn
Neither: ``` extern(C) int foo() { return 4; } unittest { assert(foo() != 4, "!= Assert triggered."); assert(foo() == 4, "== Assert triggered."); } ``` Nor: ``` int foo() { return 4; } unittest { assert(foo() != 4, "!= Assert triggered."); assert(foo() == 4, "== Assert tr

Re: unittest under betterC

2023-06-05 Thread DLearner via Digitalmars-d-learn
On Monday, 5 June 2023 at 03:42:20 UTC, ryuukk_ wrote: [...] I don't know how all this works, ... For what it is worth, running _both_ the above code fragments with: ``` dmd -main -unittest -i -run foo ``` (ie removing the -betterC flag) produces: ``` foo.d(8): [unittest] != Assert triggere

Re: unittest under betterC

2023-06-05 Thread DLearner via Digitalmars-d-learn
On Monday, 5 June 2023 at 14:25:33 UTC, Mike Parker wrote: [...] The docs say it should work: https://dlang.org/spec/betterc.html#unittests [...] Thank you for the link, can confirm that: ``` int foo() { return 4; } unittest { assert(foo() != 4, "!= Assert triggered."); assert(fo

Re: unittest under betterC

2023-06-06 Thread DLearner via Digitalmars-d-learn
On Monday, 5 June 2023 at 18:22:45 UTC, Ernesto Castellotti wrote: [...] It's not so easy to deal automatically in case of multiple modules _multiple modules_ The following code, in a batch (.bat) file, works for me: ``` @echo off :loop if [%1]==[] goto loopexit type .\%1.d > .\__temp_%1.d ech

compile-time detection of all pointer types in one test

2023-06-11 Thread DLearner via Digitalmars-d-learn
Please consider: ``` void main() { import std.stdio; struct foo { int foo1; char foo2; } foo* fooptr; void* genptr; static if (is(typeof(fooptr) == void*)) writeln("fooptr is void*"); else writeln("fooptr is not void*");

assert/static assert message format difference

2023-06-13 Thread DLearner via Digitalmars-d-learn
Only a small thing, but is it intended that: ``` void main() { // static assert (false, "Static Assert triggered"); assert(false, "Assert triggered"); } ``` produces ``` core.exception.AssertError@staticassertex01.d(4): Assert triggered ``` but removing the // produces ``` staticassertex01.d(

Re: compile-time detection of all pointer types in one test

2023-06-13 Thread DLearner via Digitalmars-d-learn
On Sunday, 11 June 2023 at 21:32:11 UTC, Andy wrote: [...] void main() { import std.stdio; struct foo {} foo* fooptr; static if (is(typeof(fooptr) == T*, T)) writeln("fooptr is a pointer to a ", T.stringof); else writeln(

static if - unexpected results

2023-06-23 Thread DLearner via Digitalmars-d-learn
Hi Was looking for compile-time detection of a struct variable. However, the following test code gave the two 'FAILS' shown below. Comments? ``` void main() { import std.stdio : writeln; import std.traits; string mxnTst(string VarName) { return `static if (is(typeof(` ~ Var

Re: static if - unexpected results

2023-06-23 Thread DLearner via Digitalmars-d-learn
On Friday, 23 June 2023 at 14:31:45 UTC, FeepingCreature wrote: On Friday, 23 June 2023 at 14:22:24 UTC, DLearner wrote: [...] ``` static assert(__traits(isPOD, int)); // ok. static assert(__traits(isPOD, byte)); // ok. ``` It's a bug in either the spec or the compiler. I am using ```

Re: static if - unexpected results

2023-06-23 Thread DLearner via Digitalmars-d-learn
On Friday, 23 June 2023 at 15:48:44 UTC, H. S. Teoh wrote: On Friday, 23 June 2023 at 15:22:36 UTC, DLearner wrote: On Friday, 23 June 2023 at 14:31:45 UTC, FeepingCreature wrote: On Friday, 23 June 2023 at 14:22:24 UTC, DLearner wrote: [...] ``` static assert(__traits(isPOD, int)); // ok

Re: static if - unexpected results

2023-06-23 Thread DLearner via Digitalmars-d-learn
On Friday, 23 June 2023 at 16:51:16 UTC, Ali Çehreli wrote: On 6/23/23 07:22, DLearner wrote: >`} else static if (__traits(isPOD, typeof(` ~ VarName ~ `))) {` ~ Regardless, you can also use the 'is' expression with the 'struct' keyword. If T is a struct,

import issue?

2023-11-22 Thread DLearner via Digitalmars-d-learn
Please, Why does: ``` // Test module Ex_mod struct SA { int SAIntFld1; int SAIntFld2; } bool AddEle(ref void* StartPtr, SA PayLoad1) { import core.stdc.stdlib : malloc; struct Ele { SA PayLoad; Ele* EleNxtPtr; Ele* ElePrvPtr; } Ele*ElePtr; Ele*

Re: import issue?

2023-11-22 Thread DLearner via Digitalmars-d-learn
On Wednesday, 22 November 2023 at 16:11:03 UTC, Richard (Rikki) Andrew Cattermole wrote: You have two ``SA`` structs, each in different encapsulations. Each of them are different, even if they have similar members. In D types that look the same do not combine, they are distinct. You can see th

Re: import issue?

2023-11-22 Thread DLearner via Digitalmars-d-learn
On Wednesday, 22 November 2023 at 16:51:54 UTC, Richard (Rikki) Andrew Cattermole wrote: On 23/11/2023 5:34 AM, DLearner wrote: Is the encapsulation issue resolved if the struct itself is held in another module, and imported from that module into both the 'main' and 'Ex_mod

mixin under -betterC

2023-11-23 Thread DLearner via Digitalmars-d-learn
Code below is intended to test simple mixin with lambda function under -betterC. Works with full-D, but fails with 'needs GC' errors under -betterC. Why is this so, bearing in mind the concatenations are executed at compile, not run, time? ``` // Test harness extern(C) void main() { i

Re: mixin under -betterC

2023-11-23 Thread DLearner via Digitalmars-d-learn
On Thursday, 23 November 2023 at 17:03:29 UTC, Julian Fondren wrote: On Thursday, 23 November 2023 at 16:33:52 UTC, DLearner wrote: Why is this so, bearing in mind the concatenations are executed at compile, not run, time? If you compile without -betterC, it'll work, but if you examine

Re: mixin under -betterC

2023-11-23 Thread DLearner via Digitalmars-d-learn
On Thursday, 23 November 2023 at 18:54:09 UTC, Julian Fondren wrote: [...] The `enum` answer? [...] No, the 'template' answer. To me, if the 'template' suggestion worked (as it did), then my simple mixin (as in my original post) should also work.

Re: mixin under -betterC

2023-11-26 Thread DLearner via Digitalmars-d-learn
On Thursday, 23 November 2023 at 17:02:58 UTC, Paul Backus wrote: [...] This is a known limitation: https://issues.dlang.org/show_bug.cgi?id=23637 [...] Sorry to come back to this, but the reference above suggests _not_ a bug in the compiler. If not a bug in the compiler, please, what is g

'typeof' question

2023-11-28 Thread DLearner via Digitalmars-d-learn
Trying to manipulate 'typeof' return strings, preferably at compile-time. e.g. to produce struct B below (intended to have an A sub-struct), from A_Ptr alone. ``` struct A { int AFld1; } A* A_Ptr; struct B { int BFld2; typeof(A_Ptr)[0..($-1)] ASUB; // Idea is ASUB of type A, from A_

Re: 'typeof' question

2023-11-28 Thread DLearner via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 18:43:37 UTC, Adam D Ruppe wrote: On Tuesday, 28 November 2023 at 18:41:49 UTC, DLearner wrote: A* A_Ptr; struct B { int BFld2; typeof(A_Ptr)[0..($-1)] ASUB; // Idea is ASUB of type A, from A_Ptr of type A*. I think what you really want is typeof

mixin issue

2023-11-29 Thread DLearner via Digitalmars-d-learn
The code: ``` void main() { struct SB { char SBChrFld1; char SBChrFld2; int SBIntFld1; int SBIntFld2; } SB SBVar; SB* wkSBPtr; void* StartPtr1 = null; mixin(mxnDelMbr("StartPtr1", "wkSBPtr")); return; } string mxnDelMbr()(string strStartPt

anonymous structs within structs

2023-12-04 Thread DLearner via Digitalmars-d-learn
Suppose we need a construct like: ``` void main() { struct A { int I1; int I2; char X; } struct B { A Dummy; int Var1; int Var2; } } ``` But do not want to give an explicit name (like 'Dummy' above) to the A struct held within the B struct. Just

Re: anonymous structs within structs

2023-12-04 Thread DLearner via Digitalmars-d-learn
On Monday, 4 December 2023 at 21:55:29 UTC, Mike Shah wrote: [...] Is something like this what you had in mind? ``` void main() { import std.stdio; mixin template A() { int I1; int I2; char X; } struct B { mixin A; int Var1; int Var2; }

Re: anonymous structs within structs

2023-12-04 Thread DLearner via Digitalmars-d-learn
On Monday, 4 December 2023 at 23:16:27 UTC, thinkunix wrote: DLearner via Digitalmars-d-learn wrote: On Monday, 4 December 2023 at 21:55:29 UTC, Mike Shah wrote: [...] Is something like this what you had in mind? ``` void main() {    import std.stdio;    mixin template A() {   int I1

Re: anonymous structs within structs

2023-12-05 Thread DLearner via Digitalmars-d-learn
On Tuesday, 5 December 2023 at 00:31:35 UTC, H. S. Teoh wrote: On Mon, Dec 04, 2023 at 11:46:45PM +, DLearner via Digitalmars-d-learn wrote: [...] Basically, B corresponds to the whole record (and only a whole record can be read). But the task only requires Var1 and Var2, the last two

Anonymous function scope issue?

2023-12-06 Thread DLearner via Digitalmars-d-learn
The two little demo scripts: ``` string mxnAdd()(string strName) { return `(typeof(` ~ strName ~ `) Pld) { import core.stdc.stdlib : malloc; struct Mst { typeof(` ~ strName ~ `) Pld; int I1; } Mst*MstPtr; MstPtr = cast(Mst*)(malloc(Mst.s

Re: mixin under -betterC

2023-12-09 Thread DLearner via Digitalmars-d-learn
On Sunday, 26 November 2023 at 15:35:39 UTC, Adam D Ruppe wrote: On Thursday, 23 November 2023 at 16:33:52 UTC, DLearner wrote: string mxnTest(string strVar1, string strVar2) { return `(int Var1, int Var2) { if (Var1 > Var2) { return true; } else { return fa

Compiler analysis fault?

2023-12-20 Thread DLearner via Digitalmars-d-learn
The code below fails to compile with Error: function `test1.foo` no `return exp;` or `assert(0);` at end of function unless the commented-out assert(0) is included. Please, what rule of D is being broken? foo does not unconditionally loop, and the only places where foo returns, it returns wit

Change to unittest?

2023-12-21 Thread DLearner via Digitalmars-d-learn
This applies to dmd version v2.106.0-dirty under Windows. Module containing several functions with unittests, no 'main' function. Was testing ok some time ago, producing '1/1 modules PASSED unittests' message. Today, ``` dmd -main -unittest -run ``` produced nothing, just a return to the com

Re: Change to unittest?

2023-12-21 Thread DLearner via Digitalmars-d-learn
On Thursday, 21 December 2023 at 10:38:16 UTC, DLearner wrote: [...] And now, returning to the problem after several hours Christmas shopping, everything seems to work perfectly!

Indirect access to variables.

2023-12-29 Thread DLearner via Digitalmars-d-learn
Compile-time: Is there a 'foo1' that yields 1 from the snippet below? ``` void main() { import std.stdio; size_t var1 = 1; char[4] Txt = cast(char[4])("var1"); writeln(foo1(Txt)); } ``` Similarly, execution-time, is there a foo2 that wields 2 from the snippet below: ``` void mai

Re: Indirect access to variables.

2023-12-30 Thread DLearner via Digitalmars-d-learn
On Friday, 29 December 2023 at 21:25:44 UTC, user1234 wrote: [...] Thanks, and the ideas are useful, but please see below, suppose: ``` void main() { size_t var1 = 1; size_t var2 = 3; size_t var3 = 5; // ... Many other variables defined. char[4] VarName; // ... // And some compl

Static array initialisation

2021-03-31 Thread DLearner via Digitalmars-d-learn
Hi I did: immutable uint MemSize=100; // Memory size in bytes. // Memory Pool ubyte[MemSize] MemPool = 8; And had a look in memory. I think the compiler set up 101 '8's, not 100 in memory. Which I did not expect. Best regards

Re: Static array initialisation

2021-03-31 Thread DLearner via Digitalmars-d-learn
On Wednesday, 31 March 2021 at 17:46:25 UTC, Imperatorn wrote: On Wednesday, 31 March 2021 at 17:27:44 UTC, DLearner wrote: Hi I did: immutable uint MemSize=100; // Memory size in bytes. // Memory Pool ubyte[MemSize] MemPool = 8; And had a look in memory. I think the compiler set up

Re: Static array initialisation

2021-03-31 Thread DLearner via Digitalmars-d-learn
On Wednesday, 31 March 2021 at 18:00:32 UTC, Steven Schveighoffer wrote: On 3/31/21 1:54 PM, DLearner wrote: On Wednesday, 31 March 2021 at 17:46:25 UTC, Imperatorn wrote: On Wednesday, 31 March 2021 at 17:27:44 UTC, DLearner wrote: Hi I did:    immutable uint  MemSize=100;  // Memory size

Re: Static array initialisation

2021-04-01 Thread DLearner via Digitalmars-d-learn
On Wednesday, 31 March 2021 at 23:21:59 UTC, russhy wrote: On Wednesday, 31 March 2021 at 17:54:38 UTC, DLearner wrote: On Wednesday, 31 March 2021 at 17:46:25 UTC, Imperatorn wrote: On Wednesday, 31 March 2021 at 17:27:44 UTC, DLearner wrote: Hi I did: immutable uint MemSize=100

Extern/scope issue

2021-04-03 Thread DLearner via Digitalmars-d-learn
'Testmain' imports module 'testmod'. Both are shown below. I expected 1,1,2,2. I got 1,0,2,1 - which speaks to scope/extern misunderstanding Any ideas? Best regards Testmain: int xvar; import testmod; void main() { import std.stdio; writeln("Entering: main"); xvar = 1; writeln("xva

Re: Extern/scope issue

2021-04-03 Thread DLearner via Digitalmars-d-learn
On Saturday, 3 April 2021 at 10:05:45 UTC, rikki cattermole wrote: On 03/04/2021 11:01 PM, DLearner wrote: [...] TLS variable with D mangling, not a c global. [...] That is a regular variable. Setting the calling convention/mangling like that doesn't make any sense and shouldn

Re: Extern/scope issue

2021-04-03 Thread DLearner via Digitalmars-d-learn
Tried the following, same result (1,0,2,1): testmain: __gshared int xvar; import testmod; void main() { import std.stdio; writeln("Entering: main"); xvar = 1; writeln("xvar=", xvar); testsub(); writeln("xvar=", xvar); writeln("Leaving: main"); } testmod: void testsub() {

Re: Extern/scope issue

2021-04-03 Thread DLearner via Digitalmars-d-learn
extern(L) extern otherQualifiersIfAny variableType variableName; //appears to be a variable declared outside of the module, so at link time a .obj file will have to declare a variable with this symbol name or else the linker will error out. ``` It seems that case 4 is what you desired but i do

  1   2   >