CBFalconer wrote:
Frank Heckenbach wrote:
... snip ...
So I'd favour something like
const Konstant: Integer; external; asmname '_c_konstant';
(i.e., mostly like a variable). But maybe also something like this would be better:
var Konstant: const Integer; external; asmname '_c_konstant';
This would probably require less syntax contortions. But in both cases, I'd have to check if it causes any parsing difficulties.
I think it would be an impossibility. Think of something like:
CONST maxindex = 123;
That's an untyped constant. That's another reason why we need a typed constant as I said. As far as you are concerned, typed constants don't exist (i.e., they're not defined in 7185), so you don't need to worry. ;-)
TYPE anindex = 1..maxindex; myarray = array[anindex] OF whatever;
VAR array1, array2 : myarray;
and think about how you can test assignment compatability at compile time,
Assignment compatibility (as far as I understand it) is no problem. array1 and array2 are of the same type and therefore compatible, and any other array type is not compatible. Remember that two identical looking structured type declarations are not compatible in Pascal, e.g.:
var a: array [1 .. 10] of Integer; b: array [1 .. 10] of Integer; [...] a := b { WRONG }
let alone indexing range checks, if that constant can be external and defined at run-time.
Then the range checks must be done at run-time as well (just like most other range checks).
I expect that: x := array1[maxindex + 1];
should generate a compile time error.
Yes, this would be nice and in principle possible I think, though also a run-time check would satisfy the requirements AFAIK.
In more complicated cases (e.g. `array1[2 * maxindex - 5]') one would need a run-time check, anyway (maxindex <= 5), and I also think that's alright then.
If maxindex is a variable, then it can be external, but we can't declare the anindex and myarray types.
Yes, we can (i.e., according to 10206). GPC currently doesn't allow it at global level (because it allocates static storage for global variables which is not suitable in these cases; we'll have to fix this sometime), but it does locally.
Frank