Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #390278

Re: Two questions on arrays with size defined by variables

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: Two questions on arrays with size defined by variables
Date 2025-02-09 22:49 -0800
Organization None to speak of
Message-ID <87cyfqpa55.fsf@nosuchdomain.example.com> (permalink)
References (3 earlier) <voae3a$2rke4$1@paganini.bofh.team> <voao29$o6uh$2@dont-email.me> <87bjvar83h.fsf@nosuchdomain.example.com> <vobna3$tmev$1@dont-email.me> <voc68c$13fkt$1@dont-email.me>

Show all headers | View raw


Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
> On 10.02.2025 03:12, Janis Papanagnou wrote:
[...]
>> 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.

In C lifetime of a non-VLA object with automatic storage duration
(defined within a block without "static") extends from when execution
reaches the opening "{" of the enclosing block to when it reaches the
closing "}".  There are well-defined ways you can even access such an
object in code that appears textually before its definition (by saving
its address and using a goto).  This means that a conforming
implementation *must* allocate memory for non-VLA automatic objects on
block entry; waiting until the definition is encountered would be
non-conforming.

But a VLA object's lifetime begins, not when execution reaches the
opening "{", but when it reaches the object definition.

[...]

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-09 08:50 +0100
  Re: Two questions on arrays with size defined by variables Andrey Tarasevich <noone@noone.net> - 2025-02-09 00:06 -0800
    Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-09 10:54 +0100
      Re: Two questions on arrays with size defined by variables Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-02-09 02:25 -0800
        Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-09 18:17 +0100
          Re: Two questions on arrays with size defined by variables Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-02-09 16:38 -0800
            Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-10 03:35 +0100
              Re: Two questions on arrays with size defined by variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-02-09 23:03 -0500
              Re: Two questions on arrays with size defined by variables Andrey Tarasevich <noone@noone.net> - 2025-02-09 20:14 -0800
                Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-10 07:43 +0100
                Re: Two questions on arrays with size defined by variables Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-02-09 22:57 -0800
                Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-10 19:33 +0100
                Re: Two questions on arrays with size defined by variables Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-02-10 14:17 -0800
      Re: Two questions on arrays with size defined by variables Michael S <already5chosen@yahoo.com> - 2025-02-09 12:39 +0200
        Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-09 18:18 +0100
          Re: Two questions on arrays with size defined by variables Michael S <already5chosen@yahoo.com> - 2025-02-09 19:57 +0200
            Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-09 19:10 +0100
            Re: Two questions on arrays with size defined by variables Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-02-09 16:46 -0800
              Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-10 02:56 +0100
      Re: Two questions on arrays with size defined by variables antispam@fricas.org (Waldek Hebisch) - 2025-02-09 14:29 +0000
        Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-09 18:19 +0100
          Re: Two questions on arrays with size defined by variables Andrey Tarasevich <noone@noone.net> - 2025-02-09 09:29 -0800
            Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-09 18:46 +0100
              Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-09 18:53 +0100
                Re: Two questions on arrays with size defined by variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-02-09 15:55 -0500
                Re: Two questions on arrays with size defined by variables antispam@fricas.org (Waldek Hebisch) - 2025-02-10 01:36 +0000
                Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-10 03:01 +0100
                Re: Two questions on arrays with size defined by variables David Brown <david.brown@hesbynett.no> - 2025-02-10 11:39 +0100
                Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-10 18:57 +0100
                Re: Two questions on arrays with size defined by variables David Brown <david.brown@hesbynett.no> - 2025-02-10 19:19 +0100
              Re: Two questions on arrays with size defined by variables Michael S <already5chosen@yahoo.com> - 2025-02-09 20:19 +0200
                Re: Two questions on arrays with size defined by variables Opus <ifonly@youknew.org> - 2025-02-10 02:44 +0100
                Re: Two questions on arrays with size defined by variables Michael S <already5chosen@yahoo.com> - 2025-02-10 12:38 +0200
                Re: Two questions on arrays with size defined by variables Opus <ifonly@youknew.org> - 2025-02-10 23:08 +0100
          Re: Two questions on arrays with size defined by variables Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-02-09 15:50 -0800
            Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-10 03:12 +0100
              Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-10 07:27 +0100
                Re: Two questions on arrays with size defined by variables Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-02-09 22:49 -0800
                Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-10 19:14 +0100
      Re: Two questions on arrays with size defined by variables Andrey Tarasevich <noone@noone.net> - 2025-02-09 07:15 -0800
        Re: Two questions on arrays with size defined by variables Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-02-09 18:20 +0100
        Re: Two questions on arrays with size defined by variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-02-09 15:34 -0500
      Re: Two questions on arrays with size defined by variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-02-09 15:27 -0500
    Re: Two questions on arrays with size defined by variables James Kuyper <jameskuyper@alumni.caltech.edu> - 2025-02-09 15:16 -0500
    Re: Two questions on arrays with size defined by variables Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-02-15 08:19 -0800

csiph-web