D - Endian ENUM
- Matthew Wilson (27/27) Sep 19 2003 I need/want to define an enum to represent endianness (in order that peo...
- Matthew Wilson (9/36) Sep 19 2003 Aaargh!
- Walter (15/59) Sep 19 2003 Write it like this:
- Matthew Wilson (5/72) Sep 19 2003 But then Ambient is not part of Endian!
- Mike Wynn (173/236) Sep 20 2003 you can do as you require ... see final verson if you not interested in
- Matthew Wilson (3/237) Sep 20 2003 I think I'll just wait for the compiler fix. ;)
- Sean L. Palmer (7/74) Sep 19 2003 You knew it was going to be an uphill battle with making version parseab...
- Matthew Wilson (8/87) Sep 19 2003 Yes, but this seems a pretty simple, and quite important, one.
- Walter (4/8) Sep 21 2003 ...)
- Matthew Wilson (35/102) Sep 19 2003 For the moment I'd satisfying myself with
- Walter (3/5) Sep 21 2003 I don't know. By itself, I don't think it offers enough.
- Nicolas Repiquet (9/19) Sep 20 2003 Cant you add to d's expressions set something like "VersionExpression :
- Nicolas Repiquet (10/12) Sep 20 2003 Endian.Big
I need/want to define an enum to represent endianness (in order that people can request an endianness to their int in the registry API). I've currently defined it in the synsoft.types module as public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } } Anyone have any violent objections? Have I missed something obvious? (I know I'm being a little optimistic in imagining D being ported to middle-endian machines, and I don't know whether we'd ever want to go byte-sexual, but what the hell!) If this is something agreeable, it'd be cool if this could go into Phobos asap, as I don't want any synsoft dependencies in the registry library when it goes into Phobos, and I'm sure you don't either. ;) Comments, please
Sep 19 2003
Aaargh! That won't even compile, since it seems that we can't have a version clause inside an enum. Oh unhappy days. :( "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjrj$2m5f$1 digitaldaemon.com...I need/want to define an enum to represent endianness (in order thatpeoplecan request an endianness to their int in the registry API). I've currently defined it in the synsoft.types module as public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } } Anyone have any violent objections? Have I missed something obvious? (IknowI'm being a little optimistic in imagining D being ported to middle-endian machines, and I don't know whether we'd ever want to go byte-sexual, but what the hell!) If this is something agreeable, it'd be cool if this could go into Phobos asap, as I don't want any synsoft dependencies in the registry librarywhenit goes into Phobos, and I'm sure you don't either. ;) Comments, please
Sep 19 2003
Write it like this: enum Endian { .... } version (LittleEndian) { const Endian Ambient = Endian.Little; } version (BigEndian) { const Endian Ambient = Endian.Big; } "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjv6$2mks$1 digitaldaemon.com...Aaargh! That won't even compile, since it seems that we can't have a versionclauseinside an enum. Oh unhappy days. :( "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjrj$2m5f$1 digitaldaemon.com...middle-endianI need/want to define an enum to represent endianness (in order thatpeoplecan request an endianness to their int in the registry API). I've currently defined it in the synsoft.types module as public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } } Anyone have any violent objections? Have I missed something obvious? (IknowI'm being a little optimistic in imagining D being ported toPhobosmachines, and I don't know whether we'd ever want to go byte-sexual, but what the hell!) If this is something agreeable, it'd be cool if this could go intoasap, as I don't want any synsoft dependencies in the registry librarywhenit goes into Phobos, and I'm sure you don't either. ;) Comments, please
Sep 19 2003
But then Ambient is not part of Endian! "Walter" <walter digitalmars.com> wrote in message news:bkgm7g$2ufv$1 digitaldaemon.com...Write it like this: enum Endian { .... } version (LittleEndian) { const Endian Ambient = Endian.Little; } version (BigEndian) { const Endian Ambient = Endian.Big; } "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjv6$2mks$1 digitaldaemon.com...(IAaargh! That won't even compile, since it seems that we can't have a versionclauseinside an enum. Oh unhappy days. :( "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjrj$2m5f$1 digitaldaemon.com...I need/want to define an enum to represent endianness (in order thatpeoplecan request an endianness to their int in the registry API). I've currently defined it in the synsoft.types module as public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } } Anyone have any violent objections? Have I missed something obvious?butknowmiddle-endianI'm being a little optimistic in imagining D being ported tomachines, and I don't know whether we'd ever want to go byte-sexual,Phoboswhat the hell!) If this is something agreeable, it'd be cool if this could go intoasap, as I don't want any synsoft dependencies in the registry librarywhenit goes into Phobos, and I'm sure you don't either. ;) Comments, please
Sep 19 2003
you can do as you require ... see final verson if you not interested in the vast array of possible error msgs from reconfiguring that same code. Matthew Wilson wrote:But then Ambient is not part of Endian! "Walter" <walter digitalmars.com> wrote in message news:bkgm7g$2ufv$1 digitaldaemon.com...I tried .... version( LittleEndian ) { private const int Endian_Ambient = Endian.Little; } else { version( BigEndian ) { private const int Endian_Ambient = Endian.Big; } else { //#error unknown endian static assert(0); } } public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 , Ambient = Endian_Ambient } // gives error enumtest.d(2): Endian.Little is not an expression then realising my error changed the int to endian (same error) so tried an alias .... version( LittleEndian ) { // private const Endian Endian_Ambient = Endian.Little; private alias Endian.Little Endian_Ambient; } else { version( BigEndian ) { // private const Endian Endian_Ambient = Endian.Big; private alias Endian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 , Ambient = Endian_Ambient } big error .... dmd: mtype.c:2685: Expression *TypeEnum::getProperty (Loc, Identifier *): Assertion `sym->memtype' failed. Aborted (linux(RH9) dmd 0.73) so moved the Endian_Ambient from before to after the enum.... public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 , Ambient = Endian_Ambient } version( LittleEndian ) { // private const Endian Endian_Ambient = Endian.Little; private alias Endian.Little Endian_Ambient; } else { version( BigEndian ) { // private const Endian Endian_Ambient = Endian.Big; private alias Endian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } enumtest.d(9): cannot implicitly convert Endian.Little to int (from the line `, Ambient = Endian_Ambient` ) so changed back to using the const Endian as oposed to alias.... (same error). so I tried a cast public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 , Ambient = cast(Endian)Endian_Ambient } version( LittleEndian ) { // private const Endian Endian_Ambient = Endian.Little; private alias Endian.Little Endian_Ambient; } else { version( BigEndian ) { // private const Endian Endian_Ambient = Endian.Big; private alias Endian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } but that's no good ... enumtest.d(9): Integer constant expression expected instead of cast(int)(Endian.Little) tried the const Endian ... got the error enumtest.d(9): Integer constant expression expected instead of cast(int)(Endian_Ambient) so thought ... lets use 2 enums (one public one private) private enum BaseEndian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 } version( LittleEndian ) { private const BaseEndian Endian_Ambient = BaseEndian.Little; // private alias BaseEndian.Little Endian_Ambient; } else { version( BigEndian ) { private const BaseEndian Endian_Ambient = BaseEndian.Big; // private alias BaseEndian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } public enum Endian { Unknown = BaseEndian.Unknown , Little = BaseEndian.Little , Big = BaseEndian.Big , Middle = BaseEndian.Middle , ByteSex = BaseEndian.ByteSex , Ambient = Endian_Ambient } that give the error enumtest.d(12): BaseEndian.Little is not an expression so resorted to the alias again .... and finally it works! Endian.Ambient is part of the enum. private enum BaseEndian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 } version( LittleEndian ) { // private const BaseEndian Endian_Ambient = BaseEndian.Little; private alias BaseEndian.Little Endian_Ambient; } else { version( BigEndian ) { // private const BaseEndian Endian_Ambient = BaseEndian.Big; private alias BaseEndian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } public enum Endian { Unknown = BaseEndian.Unknown , Little = BaseEndian.Little , Big = BaseEndian.Big , Middle = BaseEndian.Middle , ByteSex = BaseEndian.ByteSex , Ambient = Endian_Ambient }Write it like this: enum Endian { .... } version (LittleEndian) { const Endian Ambient = Endian.Little; } version (BigEndian) { const Endian Ambient = Endian.Big; } "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjv6$2mks$1 digitaldaemon.com...Aaargh! That won't even compile, since it seems that we can't have a versionclauseinside an enum. Oh unhappy days. :( "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjrj$2m5f$1 digitaldaemon.com...I need/want to define an enum to represent endianness (in order thatpeoplecan request an endianness to their int in the registry API). I've currently defined it in the synsoft.types module as public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } }
Sep 20 2003
I think I'll just wait for the compiler fix. ;) "Mike Wynn" <mike l8night.co.uk> wrote in message news:bkhkh7$1kfq$1 digitaldaemon.com...you can do as you require ... see final verson if you not interested in the vast array of possible error msgs from reconfiguring that same code. Matthew Wilson wrote:But then Ambient is not part of Endian! "Walter" <walter digitalmars.com> wrote in message news:bkgm7g$2ufv$1 digitaldaemon.com...I tried .... version( LittleEndian ) { private const int Endian_Ambient = Endian.Little; } else { version( BigEndian ) { private const int Endian_Ambient = Endian.Big; } else { //#error unknown endian static assert(0); } } public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 , Ambient = Endian_Ambient } // gives error enumtest.d(2): Endian.Little is not an expression then realising my error changed the int to endian (same error) so tried an alias .... version( LittleEndian ) { // private const Endian Endian_Ambient = Endian.Little; private alias Endian.Little Endian_Ambient; } else { version( BigEndian ) { // private const Endian Endian_Ambient = Endian.Big; private alias Endian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 , Ambient = Endian_Ambient } big error .... dmd: mtype.c:2685: Expression *TypeEnum::getProperty (Loc, Identifier *): Assertion `sym->memtype' failed. Aborted (linux(RH9) dmd 0.73) so moved the Endian_Ambient from before to after the enum.... public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 , Ambient = Endian_Ambient } version( LittleEndian ) { // private const Endian Endian_Ambient = Endian.Little; private alias Endian.Little Endian_Ambient; } else { version( BigEndian ) { // private const Endian Endian_Ambient = Endian.Big; private alias Endian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } enumtest.d(9): cannot implicitly convert Endian.Little to int (from the line `, Ambient = Endian_Ambient` ) so changed back to using the const Endian as oposed to alias.... (same error). so I tried a cast public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 , Ambient = cast(Endian)Endian_Ambient } version( LittleEndian ) { // private const Endian Endian_Ambient = Endian.Little; private alias Endian.Little Endian_Ambient; } else { version( BigEndian ) { // private const Endian Endian_Ambient = Endian.Big; private alias Endian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } but that's no good ... enumtest.d(9): Integer constant expression expected instead of cast(int)(Endian.Little) tried the const Endian ... got the error enumtest.d(9): Integer constant expression expected instead of cast(int)(Endian_Ambient) so thought ... lets use 2 enums (one public one private) private enum BaseEndian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 } version( LittleEndian ) { private const BaseEndian Endian_Ambient = BaseEndian.Little; // private alias BaseEndian.Little Endian_Ambient; } else { version( BigEndian ) { private const BaseEndian Endian_Ambient = BaseEndian.Big; // private alias BaseEndian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } public enum Endian { Unknown = BaseEndian.Unknown , Little = BaseEndian.Little , Big = BaseEndian.Big , Middle = BaseEndian.Middle , ByteSex = BaseEndian.ByteSex , Ambient = Endian_Ambient } that give the error enumtest.d(12): BaseEndian.Little is not an expression so resorted to the alias again .... and finally it works! Endian.Ambient is part of the enum. private enum BaseEndian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 } version( LittleEndian ) { // private const BaseEndian Endian_Ambient = BaseEndian.Little; private alias BaseEndian.Little Endian_Ambient; } else { version( BigEndian ) { // private const BaseEndian Endian_Ambient = BaseEndian.Big; private alias BaseEndian.Big Endian_Ambient; } else { //#error unknown endian static assert(0); } } public enum Endian { Unknown = BaseEndian.Unknown , Little = BaseEndian.Little , Big = BaseEndian.Big , Middle = BaseEndian.Middle , ByteSex = BaseEndian.ByteSex , Ambient = Endian_Ambient }Write it like this: enum Endian { .... } version (LittleEndian) { const Endian Ambient = Endian.Little; } version (BigEndian) { const Endian Ambient = Endian.Big; } "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjv6$2mks$1 digitaldaemon.com...Aaargh! That won't even compile, since it seems that we can't have a versionclauseinside an enum. Oh unhappy days. :( "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjrj$2m5f$1 digitaldaemon.com...I need/want to define an enum to represent endianness (in order thatpeoplecan request an endianness to their int in the registry API). I've currently defined it in the synsoft.types module as public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } }
Sep 20 2003
You knew it was going to be an uphill battle with making version parseable in many conceivable parts of the grammar. ;) Sean "Walter" <walter digitalmars.com> wrote in message news:bkgm7g$2ufv$1 digitaldaemon.com...Write it like this: enum Endian { .... } version (LittleEndian) { const Endian Ambient = Endian.Little; } version (BigEndian) { const Endian Ambient = Endian.Big; } "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjv6$2mks$1 digitaldaemon.com...(IAaargh! That won't even compile, since it seems that we can't have a versionclauseinside an enum. Oh unhappy days. :( "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjrj$2m5f$1 digitaldaemon.com...I need/want to define an enum to represent endianness (in order thatpeoplecan request an endianness to their int in the registry API). I've currently defined it in the synsoft.types module as public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } } Anyone have any violent objections? Have I missed something obvious?butknowmiddle-endianI'm being a little optimistic in imagining D being ported tomachines, and I don't know whether we'd ever want to go byte-sexual,Phoboswhat the hell!) If this is something agreeable, it'd be cool if this could go intoasap, as I don't want any synsoft dependencies in the registry librarywhenit goes into Phobos, and I'm sure you don't either. ;) Comments, please
Sep 19 2003
Yes, but this seems a pretty simple, and quite important, one. Over to you, big W. Relieve my burden, give me version In my enum, or I'll kick your bum! (I used to write limericks in a previous life. Not very good ones, mind ...) "Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bkgmub$30bt$1 digitaldaemon.com...You knew it was going to be an uphill battle with making version parseable in many conceivable parts of the grammar. ;) Sean "Walter" <walter digitalmars.com> wrote in message news:bkgm7g$2ufv$1 digitaldaemon.com...libraryWrite it like this: enum Endian { .... } version (LittleEndian) { const Endian Ambient = Endian.Little; } version (BigEndian) { const Endian Ambient = Endian.Big; } "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjv6$2mks$1 digitaldaemon.com...(IAaargh! That won't even compile, since it seems that we can't have a versionclauseinside an enum. Oh unhappy days. :( "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjrj$2m5f$1 digitaldaemon.com...I need/want to define an enum to represent endianness (in order thatpeoplecan request an endianness to their int in the registry API). I've currently defined it in the synsoft.types module as public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } } Anyone have any violent objections? Have I missed something obvious?butknowmiddle-endianI'm being a little optimistic in imagining D being ported tomachines, and I don't know whether we'd ever want to go byte-sexual,Phoboswhat the hell!) If this is something agreeable, it'd be cool if this could go intoasap, as I don't want any synsoft dependencies in the registrywhenit goes into Phobos, and I'm sure you don't either. ;) Comments, please
Sep 19 2003
"Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgncj$b2$1 digitaldaemon.com...Over to you, big W. Relieve my burden, give me version In my enum, or I'll kick your bum! (I used to write limericks in a previous life. Not very good ones, mind...) Good thing you switched careers!
Sep 21 2003
For the moment I'd satisfying myself with version(LittleEndian) { private const int Endian_Ambient = 1; } version(BigEndian) { private const int Endian_Ambient = 2; } public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 , Ambient = Endian_Ambient /+ version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } +/ } It's not pretty, but it works. Anyway, to the second part of the question. Is this something we'd like to see in Phobos, perhaps in "d.arch.types"? "Walter" <walter digitalmars.com> wrote in message news:bkgm7g$2ufv$1 digitaldaemon.com...Write it like this: enum Endian { .... } version (LittleEndian) { const Endian Ambient = Endian.Little; } version (BigEndian) { const Endian Ambient = Endian.Big; } "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjv6$2mks$1 digitaldaemon.com...(IAaargh! That won't even compile, since it seems that we can't have a versionclauseinside an enum. Oh unhappy days. :( "Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgjrj$2m5f$1 digitaldaemon.com...I need/want to define an enum to represent endianness (in order thatpeoplecan request an endianness to their int in the registry API). I've currently defined it in the synsoft.types module as public enum Endian { Unknown = 0 , Little = 1 , Big = 2 , Middle = 3 , ByteSex = 4 version(LittleEndian) { , Ambient = Little } version(BigEndian) { , Ambient = Big } } Anyone have any violent objections? Have I missed something obvious?butknowmiddle-endianI'm being a little optimistic in imagining D being ported tomachines, and I don't know whether we'd ever want to go byte-sexual,Phoboswhat the hell!) If this is something agreeable, it'd be cool if this could go intoasap, as I don't want any synsoft dependencies in the registry librarywhenit goes into Phobos, and I'm sure you don't either. ;) Comments, please
Sep 19 2003
"Matthew Wilson" <matthew stlsoft.org> wrote in message news:bkgnhr$uv$1 digitaldaemon.com...Anyway, to the second part of the question. Is this something we'd like to see in Phobos, perhaps in "d.arch.types"?I don't know. By itself, I don't think it offers enough.
Sep 21 2003
"Walter" <walter digitalmars.com> a écrit dans le message news: bkgm7g$2ufv$1 digitaldaemon.com...Write it like this: enum Endian { .... } version (LittleEndian) { const Endian Ambient = Endian.Little; } version (BigEndian) { const Endian Ambient = Endian.Big; }Cant you add to d's expressions set something like "VersionExpression : version ( Identifier | Integer )" that return a constant boolean ? So the following code will works : const Endian Ambient = version(LittleEndian) ? Endian.Little : Endian.Big ; Maybe "DebugExpression : debug ( Identifier | Integer )" may be added too ? -- Nicolas Repiquet
Sep 20 2003
"Nicolas Repiquet" <deadcow-remove-this free.fr> a écrit dans le message news: bki884$2ejv$1 digitaldaemon.com...const Endian Ambient = version(LittleEndian) ? Endian.Little :Endian.Big;i mean enum Endian { Little, Big, Ambient = version(LittleEndian) ? Little : Big } -- Nicolas Repiquet
Sep 20 2003