Re: Cannot alias null

2014-06-13 Thread via Digitalmars-d-learn
On Thursday, 12 June 2014 at 21:07:47 UTC, Tom Browder via Digitalmars-d-learn wrote: What I was really trying to do was D'ify C expressions like this: typedef ((struct t*)0) blah; This doesn't compile for me with GCC, and I don't know what it's supposed to mean. ((struct t*) 0) is a

Re: Cannot alias null

2014-06-13 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 12 June 2014 at 22:54:20 UTC, Ali Çehreli wrote: On 06/12/2014 03:38 PM, monarch_dodra wrote: So there's something special about null. The difference is that null is an expression. It is the same limitation as not being able to alias a literal. alias zero = 0; alias

Re: Cannot alias null

2014-06-13 Thread Tom Browder via Digitalmars-d-learn
On Fri, Jun 13, 2014 at 7:59 AM, via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Thursday, 12 June 2014 at 21:07:47 UTC, Tom Browder via Digitalmars-d-learn wrote: What I was really trying to do was D'ify C expressions like this: typedef ((struct t*)0) blah; This

Re: Cannot alias null

2014-06-13 Thread Philpax via Digitalmars-d-learn
On Friday, 13 June 2014 at 15:05:49 UTC, Tom Browder via Digitalmars-d-learn wrote: On Fri, Jun 13, 2014 at 7:59 AM, via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Thursday, 12 June 2014 at 21:07:47 UTC, Tom Browder via Digitalmars-d-learn wrote: What I was really trying

Re: Cannot alias null

2014-06-13 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 13 June 2014 at 15:05:49 UTC, Tom Browder via Digitalmars-d-learn wrote: So I'm not sure how to translate that into D. I do know my first attempt here doesn't work, even with it being surrounded by extern (C) {}: $ cat chdr.d struct t; struct t* t_ptr = null; This seems to work

Re: Cannot alias null

2014-06-13 Thread Tom Browder via Digitalmars-d-learn
On Fri, Jun 13, 2014 at 10:15 AM, monarch_dodra via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Friday, 13 June 2014 at 15:05:49 UTC, Tom Browder via Digitalmars-d-learn wrote: So I'm not sure how to translate that into D. I do know my first attempt here doesn't work,

Re: Cannot alias null

2014-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/12/2014 01:26 PM, Tom Browder via Digitalmars-d-learn wrote: This will not compile: alias blah = null; The dmd message are: di/test_hdr.d(10): Error: basic type expected, not null di/test_hdr.d(10): Error: semicolon expected to close alias declaration di/test_hdr.d(10): Error:

Re: Cannot alias null

2014-06-12 Thread Andrew Edwards via Digitalmars-d-learn
On 6/12/14, 4:29 PM, Ali Çehreli wrote: On 06/12/2014 01:26 PM, Tom Browder via Digitalmars-d-learn wrote: This will not compile: alias blah = null; The dmd message are: di/test_hdr.d(10): Error: basic type expected, not null di/test_hdr.d(10): Error: semicolon expected to

Re: Cannot alias null

2014-06-12 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 12, 2014 at 03:26:13PM -0500, Tom Browder via Digitalmars-d-learn wrote: This will not compile: alias blah = null; [...] 'null' is a value, not a type. Try: alias blah = typeof(null); T -- If it's green, it's biology, If it stinks, it's chemistry, If it has numbers

Re: Cannot alias null

2014-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/12/2014 01:36 PM, Andrew Edwards wrote: void foo() {} alias bar = foo(); Am I just misunderstanding what is meant by types? Seems to be an old behavior. That does not compile with 2.066: Error: function declaration without return type. (Note that constructors are always named

Re: Cannot alias null

2014-06-12 Thread Tom Browder via Digitalmars-d-learn
On Thu, Jun 12, 2014 at 3:42 PM, H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Thu, Jun 12, 2014 at 03:26:13PM -0500, Tom Browder via Digitalmars-d-learn wrote: This will not compile: alias blah = null; [...] 'null' is a value, not a type. Try:

Re: Cannot alias null

2014-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/12/2014 02:06 PM, Tom Browder via Digitalmars-d-learn wrote: What I was really trying to do was D'ify C expressions like this: typedef ((struct t*)0) blah; Is that actually a function pointer typedef? I can't parse that line. :) So, taking your advice, I found this to work (at

Re: Cannot alias null

2014-06-12 Thread Tom Browder via Digitalmars-d-learn
On Thu, Jun 12, 2014 at 4:17 PM, Ali Çehreli digitalmars-d-learn@puremagic.com wrote: On 06/12/2014 02:06 PM, Tom Browder via Digitalmars-d-learn wrote: ... What I was really trying to do was D'ify C expressions like this: typedef ((struct t*)0) blah; ... So, taking your advice, I found

Re: Cannot alias null

2014-06-12 Thread Adam D. Ruppe via Digitalmars-d-learn
since null is a value maybe you want enum blah = null; you may also give it a type after the enum word

Re: Cannot alias null

2014-06-12 Thread Tom Browder via Digitalmars-d-learn
On Thu, Jun 12, 2014 at 4:58 PM, Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: since null is a value maybe you want enum blah = null; That works. you may also give it a type after the enum word But I can't get any other variant to work so far. -Tom

Re: Cannot alias null

2014-06-12 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 12 June 2014 at 20:44:16 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Thu, Jun 12, 2014 at 03:26:13PM -0500, Tom Browder via Digitalmars-d-learn wrote: This will not compile: alias blah = null; [...] 'null' is a value, not a type. Try: alias blah = typeof(null);

Re: Cannot alias null

2014-06-12 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 12 June 2014 at 21:58:32 UTC, Adam D. Ruppe wrote: since null is a value maybe you want enum blah = null; you may also give it a type after the enum word I *think* the issue might be that null is an rvalue? Because you can alias variable names all you want. I do it all the time

Re: Cannot alias null

2014-06-12 Thread Ali Çehreli via Digitalmars-d-learn
On 06/12/2014 03:38 PM, monarch_dodra wrote: Yet you can alias variables... int i; alias j = i; Initially I forgot about the fact that symbols can be alias'ed as well. So that's fine. So there's something special about null. The difference is that null is an expression. It is the same