Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #143519
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: Static Arrays Inside Functions |
| Date | Sun, 28 Apr 2019 20:09:54 -0700 |
| Organization | None to speak of |
| Lines | 54 |
| Message-ID | <lnimuxy0al.fsf@kst-u.example.com> (permalink) |
| References | <qa24so02brf@news3.newsguy.com> <5cc5e100.3546998829@core> <lnr29mx9tx.fsf@kst-u.example.com> <5cc64ce6.3574620423@core> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | reader02.eternal-september.org; posting-host="4c4adbc43591da055523685449c21805"; logging-data="14475"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19nKwIBahr+RmvSBOe7q2nT" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:6txKTRRivMzvzmHwTMuH206qDvI= sha1:GQ/pbSBEEjMowU2BKRo3gZCd0L8= |
| Xref | csiph.com comp.lang.c:143519 |
Show key headers only | View raw
nobody@example.org (Scott) writes:
> On Sun, 28 Apr 2019 11:29:14 -0700, Keith Thompson <kst-u@mib.org>
> wrote:
>>nobody@example.org (Scott) writes:
>>> 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?
>>
>> {
>> int r = rand();
>> time_t now = time(NULL);
>> }
>>
>>The initial values of r and now are not stored in the object code.
>>They're computed at run time.
>
> A fair point, but those aren't initializing *values*, are they? And
> that's not quite what I was getting at in any case.
I don't know what you mean. Certainly the evalutions of the expressions
`rand()` and `time(NULL)` yield values, and those values are stored in
objects.
> Most programmers would quickly intuit that object code must
> necessarily contain all the information it needs for all of its
> initializations. I was curious about the thinking behind the question
> of whether the "code contains the values", wondering where that line
> of thinking might lead.
For a static object with an initializer, typically the object code will
contain something like a copy of the value that is to be stored in the
object. The object code is of course generated at compile time. The
value is copied into the object at load time (after the program starts
and before main() is entered).
For any object with an initializer, the compiler generates code that
results in the object being initialized during execution. The
relationship between that code and the initial values can be very
straightforward or not.
> You'll have to forgive me though. I've had a lot of IRL contact with
> beginner programmers lately, and some of them have some truly baffling
> notions.
And I'm probably not saying anything you don't already know.
--
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
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