> > Is it at all possible to duplicate the Pascal/C enum functionalityI'm sorry, this is the behavior I meant.
> > in Fortran? I know it is easy to assign parameters to specific
> > integers, and then use those parameters at runtime, however the
> > functionality I'm really looking for is the restriction that a
> > variable of enum type has to only specific enums, ie. where
> > one would get a compile time error when an enum variable was set equal
> > to another enum value not part of the former's definition, even
> > though they may both just be integers.
> Pascal and C have very different rules. In Pascal, if you declare
> Color_var := red;
> If you try to assign it a value of any other type, the compiler
> Color_var = 7;
> In Fortran you can emulate either behavior. If you want the Pascalie. similar to Arjen's reply. I'm still unsure how to structure the code such the compiler catches incorrect assignments, and how
> rules, you must define your own derived type with an integer field
> and declare your constants of that type. Each with a separate value.
> You can then assign only those constants, other variables of that
> type, or explicitly cast integers to that type (at least it's explicit).
> You could overload an assignment operator for the type to guarantee
> that explicitly cast integers were at least among the set of allowed
to define the enum to start off with. In Pascal I would have:
then in the code:
How would you emulate this in Fortran? It's the compiler error I'm particularly interested in emulating.
> Fortran 200x contains a proposal for directly implementing the C stylePoor choice. Long live Pascal.
> of enumerations. :-( This is not only unnecessary (since we can already
> emulate the C stuff), but it effectively eliminates the possibility that a
> better form of ennumerations will ever be considered.
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.