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 Jack 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. good example

Re: betterC question

2020-11-19 Thread Adam D. Ruppe via Digitalmars-d-learn
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.

Re: betterC question

2020-11-19 Thread Basile B. via Digitalmars-d-learn
On Thursday, 19 November 2020 at 00:07:12 UTC, Dibyendu Majumdar wrote: 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:

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-19 Thread Jacob Carlborg via Digitalmars-d-learn
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 You don't need the brackets to call a function (and with a little help from UFCS): void main() { import std.stdio;

Re: betterC question

2020-11-18 Thread Mike Parker via Digitalmars-d-learn
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 UFCS): void main() { import std.stdio;

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 rikki cattermole via Digitalmars-d-learn
On 19/11/2020 1:11 PM, Dibyendu Majumdar wrote: 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.

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

Re: betterC question

2020-11-18 Thread Adam D. Ruppe via Digitalmars-d-learn
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. You want to get the address.

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