Adriaan van Os wrote:
The following two programs are rejected by gpc
program redeclare1; type Int16 = Integer attribute( size = 16); Integer = Int16; {error: identifier `Integer' redeclared in a scope where an outer value was used} begin end.
program redeclare2; type Integer = Integer attribute( size = 16); {error: identifier `Integer' redeclared in a scope where an outer value was used} begin end.
The following program is accepted:
program redeclare3; type Integer = ShortInt; begin writeln( 'SizeOf( Integer) = ', SizeOf( Integer)) end.
GPC has been accepting the above first two programs. Gale Paper reminded me that this was (probably) changed in gpc-20050325 with bug fix 20050325: check identifier scopes stricter (az25.pas, fjf1059*.pas).
However, I would argue that a type definition like
int_nn = Integer attribute( size = nn);
does not "use" the Integer type as such in a strict sense. Thus, it can be treated as a special case, accepting the above two programs again. Same for the other predefined ordinal types that accept attribute( size = nn), like Word, Cardinal and Boolean.
Such declaration uses _meaning_ associated with Integer in very strict sense. Compare:
program redd1; type foo = integer; bar = foo attribute( size = 16); begin end .
program redd2; type integer = record end; bar = integer attribute( size = 16); begin end .
In the first program `bar' is an integer type of bitsize 16. In the second case `bar' is a record and size attribute is ignored. Your example in really quite like the following:
program redd3; bar = integer attribute( size = 16); integer = record end; begin end .
which is also rejected. If you compare `redd2' to `redd3' it should be clear the we do have redeclaration here.