Emil Jerabek wrote:
On Thu, Dec 05, 2002 at 05:12:49AM +0100, Frank Heckenbach wrote:
In your second form, 'Integer' is still a type, since both variables are being defined simultaniously. Therefore that one works.
Actually, I'm not sure. I'd have to check the standards again, but ISTR that an identifier cannot in one scope be used with an outer-scope meaning and be redefined. So if I'm not mistaken, GPC is
Indeed. Here are the relevant sections of the standard:
[...]
So, following these rules,
var Integer: Integer;
is invalid: "Integer" denotes a variable in the whole block containing this declaration, and in particular, on the right-hand side of this declaration, where a type-name is expected instead.
Yep. Thanks for confirming with the standard quotes.
And if you think noone would ever want to redefine `Integer' ... well, for very strict BP compatiblity we even have to do this (define it as a 16 bit type, though only in the `System' unit with a special conditional) ...
The way it is done in the System unit is invalid as well :-)
type
Integer = Integer (16);
As above, this should mean an attempt to make a circular definition. (Of course, the System unit is full of nonstandard features anyway, so this is not a real problem.)
Prof. A Olowofoyeku (The African Chief) wrote:
No. Indeed, any "unit" is non-standard by definition, since, IIUIC, neither 7185 nor 10206 understand the concept of a "unit". Therefore anyone who wants to be standards-compliant would stay well away from any source file that describes itself as a "unit".
(True, though substituting a module for the unit would make no difference WRT the other issues here.)
In fact, `Integer (16)' is non-standard already. (Is this a competition who finds the most basic non-standard usage in this statement? ;-)
Now, seeing this, I'm starting to doubt whether this syntax is useful. AFAICS, there is no easy and clean way to achieve what's wanted here. The following would be just as wrong, of course:
type Int16 = Integer (16); Integer = Int16;
The only way out might be to define Int16 in another module (here probably in the GPC module) and use it in the System unit.
For this reason (and also because `Integer (16)' is a little ambiguous, it can mean a BP-style type-cast in other contexts), I suggest to change the syntax. (IIRC, it was me who suggested it originally, so I can change it, can't I? ;-)
I guess it will affect some low-level units/modules (those that come with GPC which I'll change accordingly, of course, and maybe some of other's projects), hopefully not too many ...
Currently, we have:
Integer (n) Cardinal (n) Word (n) Boolean (n)
This could be changeg, e.g., to:
TypeOfSize (Integer, n) TypeOfSize (Word, n) TypeOfSize (Cardinal, n) TypeOfSize (Boolean, n)
This way, there would be only one new syntax, clearly distinguished from other types, and it would be extensible (e.g., someone suggested something similar for floating point types; it will probably be a little different internally and might require more parameters, but they can then fit within the parentheses, not to be confused with any other types).
Any opinions on this? (Again, all of this is meant to be used only in special situations and at the lowest possible level. Any code that uses such declarations throughout would seem quite broken to me, so this feature is not meant to support any non-standard coding practices, but rather a "fine-tuning" of some types at a low level.)
Frank