[Patch,gfortran] ENUMERATIONS and ENUMERATORS

Paul Brook paul@codesourcery.com
Mon Aug 1 14:38:00 GMT 2005


> 2) Storing the parse tree and modifications in symbol table
>
> According to the fortran standard:
>
> "The following declaration might be equivalent to the above enumeration
> definition. INTEGER(SELECTED_INT_KIND(2)), PARAMETER :: RED = 4, BLUE = 9,
> YELLOW = 10 "
>
> The enumerators that have been parsed have actually been stored as integers
> with parameter attribute
>
> and with the kind type given by (SELECTED_INT_KIND())
>
> Thus the enumeration shown in the example after parsing, will appear to the
> rest of frontend as the following statement has been parsed:
>
> INTEGER(SELECTED_INT_KIND(arg)), PARAMETER :: RED = 4, BLUE = 9, YELLOW =
> 10 "
>
> where the argument "arg" of SELECTED_INT_KIND() is decided by the following
> equation.
>
>  -10 ^ arg         < maximum of the values of all enumerators <    10^ arg 
>    -----equation
>
> the maximum values of enumerator here is 10 so
> arg by above equation comes out to be 2.

This is wrong. Section 4.6 "Enumerations and enumarators" says:

"For an enumeration the kind is selected such that an integer type with that 
kind is interoperable with the corresponding C enumeration type."

ie. you should use the same rules as the C frontend. See also the effect of 
-fshort-enums.

Paul



More information about the Fortran mailing list