Re: betterC question

2020-11-19 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 19 November 2020 at 14:34:38 UTC, Adam D. Ruppe wrote: On Thursday, 19 November 2020 at 00:20:50 UTC, Dibyendu Majumdar wrote: Okay thanks. Bad idea IMO. That's kinda how I see C taking the address of various things implicitly. To be honest it seems irrelevant what C does.

Re: betterC question

2020-11-19 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 19 November 2020 at 09:23:25 UTC, Jacob Carlborg wrote: Yes, calling `writeln` like that is a bad idea. That was a bad example. But the actual reason is, this is how D implements properties [1]. Any function that doesn't take an argument can be called without parentheses. Any

Re: betterC question

2020-11-19 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 19 November 2020 at 01:42:16 UTC, Mike Parker wrote: On Thursday, 19 November 2020 at 00:20:50 UTC, Dibyendu Majumdar wrote: On Thursday, 19 November 2020 at 00:18:54 UTC, rikki cattermole wrote: You don't need the brackets to call a function (and with a little help from

Re: betterC question

2020-11-18 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 19 November 2020 at 00:18:54 UTC, rikki cattermole wrote: You don't need the brackets to call a function (and with a little help from UFCS): void main() { import std.stdio; "Hello!".writeln; writeln; } Okay thanks. Bad idea IMO.

Re: betterC question

2020-11-18 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 19 November 2020 at 00:08:59 UTC, Adam D. Ruppe wrote: On Thursday, 19 November 2020 at 00:07:12 UTC, Dibyendu Majumdar wrote: int function() fp = test; You want to get the address. Okay that works. Thanks

Re: betterC question

2020-11-18 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 19 November 2020 at 00:08:59 UTC, Adam D. Ruppe wrote: On Thursday, 19 November 2020 at 00:07:12 UTC, Dibyendu Majumdar wrote: int function() fp = test; This tries to *call* the function test and assign its return value to fp. Really? why does it do that? You want to get

betterC question

2020-11-18 Thread Dibyendu Majumdar via Digitalmars-d-learn
I have simple test program: import core.stdc.stdio : printf; void test() { int* a; printf("a == null %d\n", a == null); } int function() fp = test; extern (C) void main() { fp(); } Why do I get: \d\dmd-2.092.1\windows\bin64\dmd.exe -betterC tests.d tests.d(5): Error: printf

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Saturday, 7 March 2020 at 14:33:29 UTC, Steven Schveighoffer wrote: It's D's version of implicit conversion. You can make the alias this a no-arg function and it will try calling that function. Okay thank you.

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Saturday, 7 March 2020 at 12:26:32 UTC, drug wrote: I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; This means that `array` can be used instead of `this`

Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi, I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; 2. The struct has no property called length - but this is referenced. Where does this come from? Thank

Re: Inline assembly question

2017-11-13 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Monday, 13 November 2017 at 18:40:42 UTC, Basile B. wrote: TBH I wonder if this is not worth a enhancement (or even a DIP) to have in asm blocks a special alias syntax... { asm { version(...) { alias First = RDI; alias Second = RSI;

Re: Inline assembly question

2017-11-13 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Sunday, 12 November 2017 at 22:40:06 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 22:00:58 UTC, Basile B. wrote: no in naked mode you have to save and restore by hand. So how does one manually generate the .pdata and .xdata sections? Are you saying that this is what I

Re: Inline assembly question

2017-11-12 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Sunday, 12 November 2017 at 22:24:08 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 22:20:46 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 22:00:58 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 21:27:28 UTC, Dibyendu Majumdar I am not sure I have understood

Re: Inline assembly question

2017-11-12 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Sunday, 12 November 2017 at 22:00:58 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 21:27:28 UTC, Dibyendu Majumdar Does the compiler generate appropriate unwind information on Win64? Prsumably if a function is marked 'naked' then it doesn't? yeah about stack frame..., also don't

Re: Inline assembly question

2017-11-12 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Sunday, 12 November 2017 at 18:48:02 UTC, Eugene Wissner wrote: https://dlang.org/spec/iasm.html#agregate_member_offsets aggregate.member.offsetof[someregister] Sorry I didn't phrase my question accurately. Presumably to use above with the mnemonics I would need additional mixin

Re: Inline assembly question

2017-11-12 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Sunday, 12 November 2017 at 12:32:09 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 12:17:51 UTC, Dibyendu Majumdar wrote: On Sunday, 12 November 2017 at 11:55:23 UTC, Eugene Wissner wrote: [...] Thank you - I probably could use something like this. It is uglier than the simpler

Re: Inline assembly question

2017-11-12 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Sunday, 12 November 2017 at 11:55:23 UTC, Eugene Wissner wrote: On Sunday, 12 November 2017 at 11:01:39 UTC, Dibyendu Majumdar wrote: I have recently started work on building a VM for Lua (actually a derivative of Lua) in X86-64 assembly. I am using the dynasm tool that is part of LuaJIT. I

Re: Inline assembly question

2017-11-12 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Sunday, 12 November 2017 at 12:00:00 UTC, Basile B. wrote: On Sunday, 12 November 2017 at 11:01:39 UTC, Dibyendu Majumdar wrote: [...] The assembly code uses static allocation of registers, but because of the differences in how registers are used in Win64 versus Unix X64 - different

Inline assembly question

2017-11-12 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi, I have recently started work on building a VM for Lua (actually a derivative of Lua) in X86-64 assembly. I am using the dynasm tool that is part of LuaJIT. I was wondering whether I could also write this in D's inline assembly perhaps, but there is one aspect that I am not sure how to

Re: Using double value in string template mixin

2016-02-26 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 26 February 2016 at 11:37:32 UTC, BBasile wrote: Erratum! Actually you can, example: import std.stdio; string foo(double a)() { return "auto value = " ~ a.stringof ~ ";"; } void main(string[] args) { mixin(foo!0.1); writeln(value); // 0.1

Re: Using double value in string template mixin

2016-02-26 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 26 February 2016 at 11:07:28 UTC, BBasile wrote: On Friday, 26 February 2016 at 11:03:43 UTC, Dibyendu Majumdar wrote: How do I use a double value in a mixin template that is generating string? Have you an example of what's failing right now to show ? I am trying something like

Using double value in string template mixin

2016-02-26 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi, How do I use a double value in a mixin template that is generating string? Thanks and Regards Dibyendu

Example of code with manual memory management

2016-02-19 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi, I am looking for example of types where memory management is manual, and the type supports operator overloading, etc. Grateful if someone could point me to sample example code. Thanks and Regards Dibyendu

Re: Disabling GC in D

2016-01-22 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 22 January 2016 at 05:15:13 UTC, Mike Parker wrote: On Thursday, 21 January 2016 at 23:06:55 UTC, Dibyendu Majumdar wrote: On Thursday, 21 January 2016 at 22:44:14 UTC, H. S. Teoh wrote: Hi - I want to be sure that my code is not allocating memory via the GC allocator; but when

Shared library question

2016-01-22 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi I am trying to create a simple shared library that exports a D function, but when I try to link to it I get errors such as: error LNK2001: unresolved external symbol _D7xxx12__ModuleInfoZ Here xxx is the module inside the shared library. I am using DMD and MS LINKER (Windows 64-bit) to

Re: How to represent struct with trailing array member

2016-01-22 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 22 January 2016 at 01:53:53 UTC, Chris Wright wrote: On Thu, 21 Jan 2016 21:52:06 +, Dibyendu Majumdar wrote: Hi I have C code where the struct has a trailing array member: struct matrix { int rows; int cols; double data[1]; }; D has bounds checking, which makes this

Re: Shared library question

2016-01-22 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 22 January 2016 at 22:06:35 UTC, Dibyendu Majumdar wrote: Hi I am trying to create a simple shared library that exports a D function, but when I try to link to it I get errors such as: error LNK2001: unresolved external symbol _D7xxx12__ModuleInfoZ I have uploaded my small

Re: Linking C libraries with DMD

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 21 January 2016 at 16:14:40 UTC, jmh530 wrote: I'm trying to understand calling C libraries from D on Windows with DMD. I made a simple example and compiled it with a static library fine (so I've converted the .h file correctly). Then, I compiled with gcc to a shared library

Re: Linking C libraries with DMD

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 21 January 2016 at 22:09:47 UTC, jmh530 wrote: The -L/LIBPATH:c:\lib gives me an error that OPTLINK : Warning 9: Unknown Option : LIBPATH and then gives the path I put is not found. At least when it's outputting the text, it's combining :C:\lib\yourlib.lib so it seemingly is

Re: Disabling GC in D

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 21 January 2016 at 22:44:14 UTC, H. S. Teoh wrote: Hi - I want to be sure that my code is not allocating memory via the GC allocator; but when shipping I don't need to disable GC - it is mostly a development check. I want to manage all memory allocation manually via malloc/free.

How to represent struct with trailing array member

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi I have C code where the struct has a trailing array member: struct matrix { int rows; int cols; double data[1]; }; In C code this is allocated dynamically to be variable size. The array is used just as normal. How should this be translated to D? Will D's array access allow data

Disabling GC in D

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
Is there a way to disable GC in D? I am aware of the @nogc qualifier but I would like to completely disable GC for the whole app/library. Regards Dibyendu

Re: Disabling GC in D

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 21 January 2016 at 22:34:43 UTC, cym13 wrote: Out of curiosity, why would you force not being able to allocate memory? Hi - I want to be sure that my code is not allocating memory via the GC allocator; but when shipping I don't need to disable GC - it is mostly a development

Re: Linking C libraries with DMD

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 21 January 2016 at 22:23:36 UTC, jmh530 wrote: Thanks. I had been trying to get 32bit code to work. I don't think I did anything special with gcc to compile the dll as 64bit. Anyway, this is what I get when I try it again (stuff in brackets I replaced). C:>dmd -m64 .d

Re: Linking C libraries with DMD

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 21 January 2016 at 22:49:06 UTC, jmh530 wrote: I'm not trying to created a shared library in D. My goal is to use a shared library from C in D. Right now, I'm working with a simple test case to make sure I could understand it before working with the actual shared library I want

Re: Linking C libraries with DMD

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 21 January 2016 at 21:55:10 UTC, jmh530 wrote: For the latter - on Windows 10 b64-bit - I am using following options for example: -shared -L/LIBPATH:c:\\lib -L//IMPLIB:mylib.lib I'm not having any luck using your options with dmd either (excluding -shared because I don't

Re: Disabling GC in D

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Thursday, 21 January 2016 at 22:15:13 UTC, Chris Wright wrote: Finally, you can use gc_setProxy() with a a GC proxy you create. Have it throw an exception instead of allocating. That means you will get crashes instead of memory leaks if something uses the GC when it shouldn't.

Re: htod question

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 22 January 2016 at 00:52:59 UTC, W.J. wrote: Counter question: What's so bad about the D std library ? I am trying to create bindings for existing C library so I was trying to use htod for that.

htod question

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
I tried using htod but got errors as it could not handle the std C header files (Visual C++). How do people work around this? Thanks and Regards Dibyendu

Re: htod question

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 22 January 2016 at 01:03:09 UTC, Dibyendu Majumdar wrote: On Friday, 22 January 2016 at 00:52:59 UTC, W.J. wrote: Counter question: What's so bad about the D std library ? I am trying to create bindings for existing C library so I was trying to use htod for that. The library

Distribution of D apps

2016-01-20 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi, I am trying to understand the options for distributing a D app to users. My assumption is that only the shared libraries and binaries need to be distributed, and I need to include the D libraries. Is this correct? Thanks and Regards Dibyendu

Re: DUB - link error on Windows 10 64-bit

2016-01-17 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Sunday, 17 January 2016 at 03:07:39 UTC, Mike Parker wrote: Have you verified that this is the only DMD installation on your path? Looks like the problem is not in dub - but the fact that a shared library in D requires a DllMain - as described in:

DUB - link error on Windows 10 64-bit

2016-01-16 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi I am using DUB on Windows 10 64-bit with DMD. I have simple project with following configuration: { "name": "testing", "description": "A minimal D application.", "copyright": "Copyright © 2016, dibyendu", "authors": ["dibyendu"], "targetType":

Re: DUB - link error on Windows 10 64-bit

2016-01-16 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Saturday, 16 January 2016 at 20:50:51 UTC, Robert M. Münch wrote: Check your paths in sc.ini Looks like the D link libraries are not found. Well as far as I can tell they are correct (unchanged from whatever the installer set them to): ; environment for both 32/64 bit [Environment]

Re: CMake support for D

2016-01-04 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Monday, 4 January 2016 at 08:28:03 UTC, Luis wrote: I suggest use dub instead of cmake. I did a try to use cmake some time ago (a few years ago, before dub), and was a nightmare to get ir working on GNU/Linux and Windows. With dub , simply works fine with a simple json file. CMake has

CMake support for D

2016-01-03 Thread Dibyendu Majumdar via Digitalmars-d-learn
Does CMake recognise D in the enable_language command? If not is there a workaround? Thanks and Regards Dibyendu