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

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

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!

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

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

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 false;

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 =

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

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-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; }

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.

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

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' 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

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

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-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 the

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() {

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' files? Each

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

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;

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, is (T == struct) that

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 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 ``` DMD64

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(` ~

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

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 ```

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*");

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

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.");

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

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

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,

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

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 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

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: 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.

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

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;

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

'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

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

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

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-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-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 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>dmd

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 declarator

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

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

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

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

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

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

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

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] =

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

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

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:

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

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 package and

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-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-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-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

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread DLearner via Digitalmars-d-learn
On Saturday, 16 October 2021 at 19:29:59 UTC, Dennis wrote: On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote: How does one obtain from strVar: 1. The type of fooVar; `typeof(mixin(strVar))` 2. The value of fooVar? `mixin(strVar)` ``` void main() { import std.stdio;

Obtaining type and value of a variable named in another variable

2021-10-16 Thread DLearner via Digitalmars-d-learn
Hi Suppose string variable strVar has value "fooVar". fooVar is a valid variable name used elsewhere in the program. How does one obtain from strVar: 1. The type of fooVar; 2. The value of fooVar? Best regards

Re: uint overflow behaviour

2021-09-15 Thread DLearner via Digitalmars-d-learn
Thanks for the responses.

uint overflow behaviour

2021-09-15 Thread DLearner via Digitalmars-d-learn
Please confirm that if the addition of two uint variables produces a result larger than can be held in a uint: 1. This is a D-legal operation (however inadvisable!), with the D-defined result of wraparound; 2. Emphasing 1. above: the result is not undefined, or an error (by the rules of D),

Re: Run-time setting of immutable variable?

2021-09-03 Thread DLearner via Digitalmars-d-learn
On Thursday, 2 September 2021 at 23:12:28 UTC, Steven Schveighoffer wrote: [...] immutable means "I can never change and *everything I point at* can never change". [...] If that is how the language defines the keyword 'immutable' when used in the definition of a pointer variable, then so

Re: Run-time setting of immutable variable?

2021-09-02 Thread DLearner via Digitalmars-d-learn
On Thursday, 2 September 2021 at 16:46:46 UTC, Steven Schveighoffer wrote: On 9/2/21 12:01 PM, DLearner wrote: Suppose there is a variable that is set once per run, and is (supposed) never to be altered again.  However, the value to which it is set is not known at compile time. Example below,

Run-time setting of immutable variable?

2021-09-02 Thread DLearner via Digitalmars-d-learn
Suppose there is a variable that is set once per run, and is (supposed) never to be altered again. However, the value to which it is set is not known at compile time. Example below, variable is 'ArrPtr'; ``` ubyte[10] Arr; // immutable void* ArrPtr; void* ArrPtr; void main() { ArrPtr =

Re: Scope of Mixins

2021-08-26 Thread DLearner via Digitalmars-d-learn
On Thursday, 26 August 2021 at 16:28:22 UTC, Adam D Ruppe wrote: On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote: Please confirm that mixins of format: You really shouldn't use string mixins like this at all. If you want to work with a variable, pass the variable itself as an

Re: Scope of Mixins

2021-08-26 Thread DLearner via Digitalmars-d-learn
On Thursday, 26 August 2021 at 16:28:22 UTC, Adam D Ruppe wrote: On Thursday, 26 August 2021 at 16:16:55 UTC, DLearner wrote: Please confirm that mixins of format: You really shouldn't use string mixins like this at all. If you want to work with a variable, pass the variable itself as an

Scope of Mixins

2021-08-26 Thread DLearner via Digitalmars-d-learn
Please confirm that mixins of format: ``` string mxn1(string VarName) { ... } ``` Invoked like: ``` mixin(mxn1("Var1")); ``` Have a wider scope than mixins like: ``` string mxn2(string VarName)() { ... } ``` Invoked like: ``` mixin(mxn2!"Var2"); ``` I tried direct replacement of former

Re: Mixin/static if issue

2021-08-25 Thread DLearner via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 22:57:23 UTC, jfondren wrote: Contrast: [...] ```d void main() { import std.stdio; uint TestVar = 5; string mxnWrite_Size_t(string VarName)() { static if (typeof(mixin(VarName)).stringof == "uint") { return `write("` ~ VarName ~

Re: Mixin/static if issue

2021-08-25 Thread DLearner via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 22:33:00 UTC, H. S. Teoh wrote: [...} I think what you meant to write is: static if (typeof(mixin(VarName)).stringof == "uint") { You want the type of the variable named by VarName, not the type of VarName. T I understand your reasoning, but: ```

Mixin/static if issue

2021-08-25 Thread DLearner via Digitalmars-d-learn
Please see below: ``` void main() { import std.stdio; uint TestVar = 5; string mxnWrite_Size_t(string VarName) { static if (typeof(VarName).stringof == "uint") { return `write("` ~ VarName ~ `");`; } else { return `writeln("Apparently TestVar not a

Unexpected result comparing to null

2021-08-23 Thread DLearner via Digitalmars-d-learn
Hi The code below compiles and runs producing 'Not null'. ``` void main() { import std.stdio; int Var1; int* ptrVar; ptrVar = if (ptrVar == null) { writeln("Null"); } else { writeln("Not null"); } } ``` However, should it not fail to compile, as '=='

DMD compiler - warning of unused variables

2021-08-16 Thread DLearner via Digitalmars-d-learn
Hi Please see code below: ``` void main() { import std.stdio; size_t i; size_t j; i = 5; writeln("i = ",i); } ``` Is there a compiler option that would warn that variable 'j' is defined but not used? Best regards

Routing of AssertError messages

2021-07-31 Thread DLearner via Digitalmars-d-learn
Hi This may be due to Windows, not DMD. Please see code below (held in test.d): ``` void main() { import std.stdio; writeln("Test"); assert(false, "TestAssert"); } ``` ` dmd -i -run test.d ` results in both "Test" and the "TestAssert" string (and trace) being routed to screen. But

Re: Scope of enum

2021-07-11 Thread DLearner via Digitalmars-d-learn
On Sunday, 11 July 2021 at 12:47:48 UTC, Adam D Ruppe wrote: On Sunday, 11 July 2021 at 12:37:20 UTC, DLearner wrote: C:\Users\SoftDev\Documents\BDM\D\Examples\CTFE\T2>type k_mod.d // k_mod.d ubyte[MemSiz] MemPool; You didn't import the other module here. D's imports aren't like C's

Re: Scope of enum

2021-07-11 Thread DLearner via Digitalmars-d-learn
On Sunday, 11 July 2021 at 12:01:27 UTC, jfondren wrote: On Sunday, 11 July 2021 at 10:58:58 UTC, DLearner wrote: Is there a way of forcing DMD to extend the scope of `MemSiz` to include `k_mod`? Best regards ``` $ cat k_mod.d import test01; ubyte[MemSiz] MemPool; $ cat test01.d enum

Scope of enum

2021-07-11 Thread DLearner via Digitalmars-d-learn
Please see the two code snippets below: ``` // test01.d enum MemSiz = 240; void main() { import k_mod; } ``` and ``` // k_mod.d ubyte[MemSiz] MemPool; ``` A number of tests need to be run on code in `k_mod`, with different sizes of the static array `MemPool` in each test. So each test

assert(false) and GC

2021-07-08 Thread DLearner via Digitalmars-d-learn
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

Re: Scope of import

2021-05-15 Thread DLearner via Digitalmars-d-learn
On Saturday, 15 May 2021 at 11:38:22 UTC, Adam D. Ruppe wrote> Just use ``` dmd -i main.d instead. It will be about 2x faster and more reliable. ``` Your suggestion worked. Thank you.

Re: Scope of import

2021-05-15 Thread DLearner via Digitalmars-d-learn
On Saturday, 15 May 2021 at 07:19:08 UTC, Mike Parker wrote: Then it must be an issue with rdmd... rdmd build 20210311 Running under Win-10.

Re: Scope of import

2021-05-15 Thread DLearner via Digitalmars-d-learn
On Saturday, 15 May 2021 at 07:05:00 UTC, Mike Parker wrote: That's odd. What's your command line? rdmd main.d

Scope of import

2021-05-15 Thread DLearner via Digitalmars-d-learn
``` // main void main() { import A; // import B; import std.stdio; writeln("Entered main"); fnA1(); writeln("Leaving main"); } ``` ``` module A; void fnA1() { import B; import std.stdio; writeln("Entered fnA1"); fnB1(); writeln("Leaving fnA1"); } ``` ```

Can rdmd (under Windows 10) use linker other than Optlink?

2021-05-14 Thread DLearner via Digitalmars-d-learn
I am getting 'Error 42: Symbol Undefined' while testing some (fairly) complex imports. There was a reference in January to an Optlink bug that seemed like it could be responsible. If rdmd can use another linker (and one was recommended), I might be able to test things further. Best

Scope of 'alias'

2021-05-14 Thread DLearner via Digitalmars-d-learn
>>> void foo(pint p1) { alias pint=uint; import std.stdio; writeln("p1 = ", p1); } void main() { alias pint=uint; pint var1; var1 = 7; foo(var1); } <<< Does not compile. But the rather similar: alias pint=uint; void

Pointer indirections

2021-05-04 Thread DLearner via Digitalmars-d-learn
Hi Is there any limitation as to the number of pointer indirections? I have a construct: a.b.c.d = x; where all the variables are pointers to struct (the same struct). This fails with 'Access Violation', but if I change the code to: temp = a.b.c; temp.d = x; everything seems to work.

Re: Extern/scope issue

2021-04-03 Thread DLearner via Digitalmars-d-learn
On Saturday, 3 April 2021 at 13:50:27 UTC, ag0aep6g wrote: On 03.04.21 15:34, DLearner wrote: The following produces the expected result. However, changing extern(C) to extern(D) causes linker failures. To me, that is bizarre. Testmain: extern(C) int xvar; [...] Testmod: extern extern(C)

Re: Extern/scope issue

2021-04-03 Thread DLearner via Digitalmars-d-learn
On Saturday, 3 April 2021 at 13:38:25 UTC, rikki cattermole wrote: On 04/04/2021 2:34 AM, DLearner wrote: However, changing extern(C) to extern(D) causes linker failures. To me, that is bizarre. extern(D) sets the ABI AND mangling. D mangling incorporates things like the module name. I'm

Re: Extern/scope issue

2021-04-03 Thread DLearner via Digitalmars-d-learn
The __gshared is irrelevant to it working between modules, but it is relevant if you want C compatibility between threads (NOTE: extern(C) sets mangling, otherwise the module would be encoded in its name). Solved: The following produces the expected result. However, changing extern(C) to

Re: Extern/scope issue

2021-04-03 Thread DLearner via Digitalmars-d-learn
https://dlang.org/spec/attribute.html#gshared However, you should be using the module system for accessing globals, rather than redeclaring them. If the module system is dumped, and evrything put into one file, works perfectly. With or without __gshared in from of 'int xvar'. int xvar;

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

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
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't be

  1   2   >