digitalmars.D.learn - Emulate C's (polymorphic) NULL type
- ParticlePeter (8/8) Jun 06 2016 In C NULL can be used as integer as well as null pointer.
- Anonymouse (4/12) Jun 06 2016 If you want it for use in logical expressions then implicit
- ParticlePeter (4/21) Jun 06 2016 I don't see the connection here, you introduced two symbols with
- Anonymouse (2/5) Jun 06 2016 Ah, my apologies, I misunderstood the question.
- Anonymouse (2/3) Jun 06 2016 Missed this bit. Not sure about that one.
- Alex Parrill (5/13) Jun 06 2016 I already asked about this:
- ParticlePeter (3/21) Jun 06 2016 O.k., my web search didn't find that topic. The last reply looks
- ParticlePeter (2/26) Jun 06 2016 Lets bump it and discuss there.
- Alex Parrill (5/29) Jun 06 2016 That's the ABI hack I mentioned. It abuses the fact that on most
In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow?
Jun 06 2016
On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote:In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow?If you want it for use in logical expressions then implicit boolean conversion will treat them as the same. https://dpaste.dzfl.pl/d82f60657c37
Jun 06 2016
On Monday, 6 June 2016 at 11:40:11 UTC, Anonymouse wrote:On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote:I don't see the connection here, you introduced two symbols with two different types. I want one symbol which can pose as two different (constant) types.In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow?If you want it for use in logical expressions then implicit boolean conversion will treat them as the same. https://dpaste.dzfl.pl/d82f60657c37
Jun 06 2016
On Monday, 6 June 2016 at 12:09:33 UTC, ParticlePeter wrote:I don't see the connection here, you introduced two symbols with two different types. I want one symbol which can pose as two different (constant) types.Ah, my apologies, I misunderstood the question.
Jun 06 2016
On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote:A extern( C ) function should be able to take it as either one.Missed this bit. Not sure about that one.
Jun 06 2016
On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote:In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow?I already asked about this: https://forum.dlang.org/post/bnkqevhyxwdjjxscteus forum.dlang.org Tldr; doesn't seem to be possible without multiple alias this or using ABI hacks.
Jun 06 2016
On Monday, 6 June 2016 at 16:19:02 UTC, Alex Parrill wrote:On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote:O.k., my web search didn't find that topic. The last reply looks promising, wouldn't that work?In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow?I already asked about this: https://forum.dlang.org/post/bnkqevhyxwdjjxscteus forum.dlang.org Tldr; doesn't seem to be possible without multiple alias this or using ABI hacks.
Jun 06 2016
On Monday, 6 June 2016 at 18:33:36 UTC, ParticlePeter wrote:On Monday, 6 June 2016 at 16:19:02 UTC, Alex Parrill wrote:Lets bump it and discuss there.On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote:O.k., my web search didn't find that topic. The last reply looks promising, wouldn't that work?In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow?I already asked about this: https://forum.dlang.org/post/bnkqevhyxwdjjxscteus forum.dlang.org Tldr; doesn't seem to be possible without multiple alias this or using ABI hacks.
Jun 06 2016
On Monday, 6 June 2016 at 18:33:36 UTC, ParticlePeter wrote:On Monday, 6 June 2016 at 16:19:02 UTC, Alex Parrill wrote:That's the ABI hack I mentioned. It abuses the fact that on most hardware and compiled, a pointer and a structure containing a single pointer have the same binary representation. It will likely work, but it isn't guarenteed.On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote:O.k., my web search didn't find that topic. The last reply looks promising, wouldn't that work?In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow?I already asked about this: https://forum.dlang.org/post/bnkqevhyxwdjjxscteus forum.dlang.org Tldr; doesn't seem to be possible without multiple alias this or using ABI hacks.
Jun 06 2016