September 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...
> >
> >>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 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 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
> >>>>      }
> >>>>    }
> >>>>
> >
>
> 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
> }
>
>
>
>


September 21, 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!


September 21, 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.


1 2
Next ›   Last »