Sujet : Re: Two questions on arrays with size defined by variables
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 10. Feb 2025, 03:12:18
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vobna3$tmev$1@dont-email.me>
References :  1 2 3 4 5 6
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
 On 10.02.2025 00:50, Keith Thompson wrote:
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
[...]
I had other languages in mind.[*]
>
Janis
>
[*] For example Simula:
>
begin
    integer n;
    n := inint;
    begin
        integer array arr (1:n);
        arr(5) := 9;
    end
end
>
(Which is also understandable, since in Simula declarations must appear
before statements in any block.)
 
Apparently Simula doesn't allow variables to be initialized in their
declarations. 
The Cim compiler I use actually supports a constant initialization -
but I'm positive this is non-standard! - like
begin
    integer n = 10;
    integer array arr (1:n);
    arr(5) := 9;
end
Because of that, `n := inint;` (where inint is actually a
call to a value-returning procedure) is a separate statement.  If
Simula supported C-style initializers, then presumably the inner block
would not be needed:
Indeed. (See non-standard example above.)
 
    begin
        integer n := inint;
        integer array arr (1:n);
        arr(5) := 9;
    end
 
This is not possible because 'n' isn't a constant here (and 'inint' is
a function, as you say). - So you're correct that the block would not
be an inherent necessity for that declaration [with Cim compiler].
A general statement for the standard Simula language cannot be given,
though, since it's undefined.
Janis