About Alias and Enum

Forum for discussion about the documentation project.
Post Reply
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

About Alias and Enum

Post by Tourist Trap »

Hello,

Some remarks:
  • Alias doc page doesn't refer to TYPE ALIAS whereas maybe this can be what the user is looking for.
  • Type..End Type refers to TYPE ALIAS but not Enum..End Enum. Sad because one may not think that something like in the example below is possible. It can anyway be a very useful encouragement to use ENUMs within types, because we can reduce the weight of access (without aliases the names can become very long).

Code: Select all

type SOMETYPEEXAMPLE
    enum _SOMEENUMEXAMPLE
        a = 999
        b = 111
    end enum
    as integer  i
end type
type _ENU  as SOMETYPEEXAMPLE._SOMEENUMEXAMPLE
? _ENU.a
? _ENU.b
sleep
Not sure, but I think that See Also sections in both case could include this page.
In all the case Type Alias is worth reading because it gives good overview for a search around this concept, short and clear useful page.
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: About Alias and Enum

Post by fxm »

A better example could be using the qualifier 'Explicit' for 'Enum', otherwise the enum name can be omitted in expressions.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: About Alias and Enum

Post by Tourist Trap »

fxm wrote:A better example could be using the qualifier 'Explicit' for 'Enum', otherwise the enum name can be omitted in expressions.
In general you will have to specify everything:

Code: Select all

type SOMETYPEEXAMPLE
    enum _ENUM1
        a
        b
    end enum
    enum _ENUM2
        a
        b
    end enum
    as integer  i
end type
? SOMETYPEEXAMPLE.a
? SOMETYPEEXAMPLE.b
''error 254: Ambiguous symbol access, explicit scope resolution required

sleep
I know that many people don't bother being explicit with enums but probably this is the C feature. When embedded in types, the name of the content is very unlikely to be enough without the name of the container. And personaly I use the name of the container as an information readable without comment in the code. The values of enum constants generally are useless. And I don't know if FB can make them do bitwise stuff, to work with AND/OR operators.
Post Reply