Re: Two questions on arrays with size defined by variables

Liste des GroupesRevenir à cl c 
Sujet : Re: Two questions on arrays with size defined by variables
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.c
Date : 10. Feb 2025, 07:27:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <voc68c$13fkt$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 10.02.2025 03:12, Janis Papanagnou wrote:
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
 

I should have noted that this (non-standard) syntax doesn't really
address the problem (since you have just a named constant that you
may use in several places, but the array is *not* really dynamic,
its memory demands are fixed and known for that block).

I think the primary point for an explanation of the necessity of a
block structure is different. - It is typical that stack memory is
allocated when a block is "entered". For the stack allocation the
size of all local objects should be known. But in the first example
above the outer block has only knowledge about the size of the 'n'
integer variable, but without a concrete value for 'n' we don't
know how many space the dynamic array will need. But if we open a
new (subordinated) block the array size is determined if declared
there.

BTW, this is also true for Algol 60, which is effectively a subset
of Simula.

 
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].

So, given my above stack memory argumentation, I'd have to withdraw
my agreement; and not only because it's irrelevant (in several ways).

A general statement for the standard Simula language cannot be given,
though, since it's undefined.
 
Janis
 


Date Sujet#  Auteur
9 Feb 25 * Two questions on arrays with size defined by variables45Janis Papanagnou
9 Feb 25 `* Re: Two questions on arrays with size defined by variables44Andrey Tarasevich
9 Feb 25  +* Re: Two questions on arrays with size defined by variables41Janis Papanagnou
9 Feb 25  i+* Re: Two questions on arrays with size defined by variables10Keith Thompson
9 Feb 25  ii`* Re: Two questions on arrays with size defined by variables9Janis Papanagnou
10 Feb 25  ii `* Re: Two questions on arrays with size defined by variables8Keith Thompson
10 Feb 25  ii  `* Re: Two questions on arrays with size defined by variables7Janis Papanagnou
10 Feb 25  ii   +- Re: Two questions on arrays with size defined by variables1James Kuyper
10 Feb 25  ii   `* Re: Two questions on arrays with size defined by variables5Andrey Tarasevich
10 Feb 25  ii    `* Re: Two questions on arrays with size defined by variables4Janis Papanagnou
10 Feb 25  ii     `* Re: Two questions on arrays with size defined by variables3Keith Thompson
10 Feb 25  ii      `* Re: Two questions on arrays with size defined by variables2Janis Papanagnou
10 Feb 25  ii       `- Re: Two questions on arrays with size defined by variables1Keith Thompson
9 Feb 25  i+* Re: Two questions on arrays with size defined by variables6Michael S
9 Feb 25  ii`* Re: Two questions on arrays with size defined by variables5Janis Papanagnou
9 Feb 25  ii `* Re: Two questions on arrays with size defined by variables4Michael S
9 Feb 25  ii  +- Re: Two questions on arrays with size defined by variables1Janis Papanagnou
10 Feb 25  ii  `* Re: Two questions on arrays with size defined by variables2Keith Thompson
10 Feb 25  ii   `- Re: Two questions on arrays with size defined by variables1Janis Papanagnou
9 Feb 25  i+* Re: Two questions on arrays with size defined by variables20Waldek Hebisch
9 Feb 25  ii`* Re: Two questions on arrays with size defined by variables19Janis Papanagnou
9 Feb 25  ii +* Re: Two questions on arrays with size defined by variables13Andrey Tarasevich
9 Feb 25  ii i`* Re: Two questions on arrays with size defined by variables12Janis Papanagnou
9 Feb 25  ii i +* Re: Two questions on arrays with size defined by variables7Janis Papanagnou
9 Feb 25  ii i i`* Re: Two questions on arrays with size defined by variables6James Kuyper
10 Feb 25  ii i i +- Re: Two questions on arrays with size defined by variables1Waldek Hebisch
10 Feb 25  ii i i `* Re: Two questions on arrays with size defined by variables4Janis Papanagnou
10 Feb 25  ii i i  `* Re: Two questions on arrays with size defined by variables3David Brown
10 Feb 25  ii i i   `* Re: Two questions on arrays with size defined by variables2Janis Papanagnou
10 Feb 25  ii i i    `- Re: Two questions on arrays with size defined by variables1David Brown
9 Feb 25  ii i `* Re: Two questions on arrays with size defined by variables4Michael S
10 Feb 25  ii i  `* Re: Two questions on arrays with size defined by variables3Opus
10 Feb 25  ii i   `* Re: Two questions on arrays with size defined by variables2Michael S
10 Feb 25  ii i    `- Re: Two questions on arrays with size defined by variables1Opus
10 Feb 25  ii `* Re: Two questions on arrays with size defined by variables5Keith Thompson
10 Feb 25  ii  `* Re: Two questions on arrays with size defined by variables4Janis Papanagnou
10 Feb 25  ii   `* Re: Two questions on arrays with size defined by variables3Janis Papanagnou
10 Feb 25  ii    `* Re: Two questions on arrays with size defined by variables2Keith Thompson
10 Feb 25  ii     `- Re: Two questions on arrays with size defined by variables1Janis Papanagnou
9 Feb 25  i+* Re: Two questions on arrays with size defined by variables3Andrey Tarasevich
9 Feb 25  ii+- Re: Two questions on arrays with size defined by variables1Janis Papanagnou
9 Feb 25  ii`- Re: Two questions on arrays with size defined by variables1James Kuyper
9 Feb 25  i`- Re: Two questions on arrays with size defined by variables1James Kuyper
9 Feb 25  +- Re: Two questions on arrays with size defined by variables1James Kuyper
15 Feb17:19  `- Re: Two questions on arrays with size defined by variables1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal