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


Groups > comp.lang.c > #143516

Re: Static Arrays Inside Functions

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Static Arrays Inside Functions
Date 2019-04-28 13:50 -0700
Organization None to speak of
Message-ID <lnmuk9yhu6.fsf@kst-u.example.com> (permalink)
References <qa24so02brf@news3.newsguy.com> <5cc5e100.3546998829@core> <5cc5fcff$0$3529$426a74cc@news.free.fr>

Show all headers | View raw


Mateusz Viste <mateusz@wont.tell> writes:
> On Sun, 28 Apr 2019 17:26:27 +0000, Scott wrote:
>> On 27 Apr 2019 17:52:24 GMT, "F. Russell" <fr@random.info> wrote:
>>>Will the array be initialized during compile time so that the function
>>>code contains the values?
>> 
>> Not to belabor the obvious related issue, but if you have *any*
>> initialized variable, where would you expect those initializing values
>> to be stored if not in the object code?
>
> "easy" initializations could just as well be initialized by the compiler 
> at run-time, when the program starts, instead of storing kilobytes of 
> zero bytes or so inside the executable.

Right.  Typically if you have these definitions at file scope:

    char zero[1024];
    char non_zero[1024] = { /* 1024 values here */ };

you'll have 1024 bytes of data in the object file holding the
initialized value for `non_zero`, and small amount of information
causing 1024 bytes to be allocated and zeroed for `zero`.

A small quibble: it's not "initialized by the compiler at run-time".
At run-time, the compiler is not running, and might not even exist
on the system.  The compiler generates code that causes allocation
and initialization to occur at load time and/or at run time.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

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


Thread

Static Arrays Inside Functions "F. Russell" <fr@random.info> - 2019-04-27 17:52 +0000
  Re: Static Arrays Inside Functions Bart <bc@freeuk.com> - 2019-04-27 19:03 +0100
    Re: Static Arrays Inside Functions Keith Thompson <kst-u@mib.org> - 2019-04-27 13:14 -0700
      Re: Static Arrays Inside Functions David Brown <david.brown@hesbynett.no> - 2019-04-28 00:10 +0200
  Re: Static Arrays Inside Functions Siri Cruise <chine.bleu@yahoo.com> - 2019-04-27 13:40 -0700
  Re: Static Arrays Inside Functions nobody@example.org (Scott) - 2019-04-28 17:26 +0000
    Re: Static Arrays Inside Functions Keith Thompson <kst-u@mib.org> - 2019-04-28 11:29 -0700
      Re: Static Arrays Inside Functions nobody@example.org (Scott) - 2019-04-29 01:17 +0000
        Re: Static Arrays Inside Functions Keith Thompson <kst-u@mib.org> - 2019-04-28 20:09 -0700
        Re: Static Arrays Inside Functions "F. Russell" <fr@random.info> - 2019-04-29 10:33 +0000
          Re: Static Arrays Inside Functions Bart <bc@freeuk.com> - 2019-04-29 11:49 +0100
          Re: Static Arrays Inside Functions Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-04-29 04:50 -0700
          Re: Static Arrays Inside Functions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-04-29 17:36 +0100
          Re: Static Arrays Inside Functions Keith Thompson <kst-u@mib.org> - 2019-04-29 15:24 -0700
      Re: Static Arrays Inside Functions Ike Naar <ike@iceland.freeshell.org> - 2019-04-29 05:50 +0000
        Re: Static Arrays Inside Functions Ike Naar <ike@iceland.freeshell.org> - 2019-04-29 05:51 +0000
        Re: Static Arrays Inside Functions Keith Thompson <kst-u@mib.org> - 2019-04-29 00:04 -0700
          Re: Static Arrays Inside Functions Ike Naar <ike@iceland.freeshell.org> - 2019-04-29 15:06 +0000
    Re: Static Arrays Inside Functions Mateusz Viste <mateusz@wont.tell> - 2019-04-28 19:20 +0000
      Re: Static Arrays Inside Functions Keith Thompson <kst-u@mib.org> - 2019-04-28 13:50 -0700
  Re: Static Arrays Inside Functions James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-04-29 00:44 -0400

csiph-web