Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: nested while loop computing triangular number - issues |
| Date | 2015-07-15 13:19 -0700 |
| Organization | None to speak of |
| Message-ID | <lnd1ztjhqv.fsf@kst-u.example.com> (permalink) |
| References | (2 earlier) <5abf1a27-ebbf-4c5d-89d9-e0b8fc6efd04@googlegroups.com> <lnmvz2pdd0.fsf@kst-u.example.com> <7e623eb8-4156-443c-b637-ffe06d4e87de@googlegroups.com> <lntwt9mcuf.fsf@kst-u.example.com> <kfnio9lqoy8.fsf@x-alumni2.alumni.caltech.edu> |
Tim Rentsch <txr@alumni.caltech.edu> writes:
> Keith Thompson <kst-u@mib.org> writes:
>> [snip]
>>
>> Incidentally, one thing I dislike about compound literals is
>> that the storage duration of the object depends only on the
>> context in which it appears. A string literal always creates an
>> array object with static storage duration. A compound literal
>> creates an object with static storage duration if it occurs
>> outside a function, or with automatic storage duration if it
>> occurs inside a function. [snip] there are times it would be
>> convenient to have a block-scope compound literal that refers to
>> a static object.
>>
>> I might suggest an enhancement that permits something like:
>>
>> (static struct foo){1, 0, 1, 0};
>>
>> at block scope. (Of course non-constant expressions would not
>> be permitted.)
>
> I don't know why you think this would be useful. If the value is
> used only for its value (ie, and the address is not taken),
> simply leave off the 'static' and let the compiler notice that
> the value can be initialized and kept statically. If the address
> is made use of, but the contents are not modified, writing the
> compound literal with 'const' in the type should let the compiler
> notice that the value can be allocated statically as well (ie,
> even though there was no mention of 'static').
[...]
I was thinking of compound literals as analogous to string literals.
It's certainly useful to be able to assign a string literal to a
`const char*` object, and for that string to continue to exist outside
the scope in which it appears.
{
...
obj->name = "Fred";
...
}
It would be awkward of the char array containing "Fred" were to vanish
at the closing brace. I can imagine something similar for, say, a
structure rather than a character array.
I don't have a concrete example off the top of my head -- and a
non-const static object could cause problems if you're not careful.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 06:31 -0700
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 06:52 -0700
Re: nested while loop computing triangular number - issues Siri Cruz <chine.bleu@yahoo.com> - 2015-07-11 07:07 -0700
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 07:27 -0700
Re: nested while loop computing triangular number - issues Siri Cruz <chine.bleu@yahoo.com> - 2015-07-11 08:19 -0700
Re: nested while loop computing triangular number - issues Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-11 15:28 +0100
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 08:01 -0700
Re: nested while loop computing triangular number - issues James Kuyper <jameskuyper@verizon.net> - 2015-07-11 12:24 -0400
Re: nested while loop computing triangular number - issues Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-11 21:24 +0100
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-12 09:35 -0700
Re: nested while loop computing triangular number - issues Keith Thompson <kst-u@mib.org> - 2015-07-12 11:55 -0700
Re: nested while loop computing triangular number - issues Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-12 22:14 +0100
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-13 08:05 -0700
Re: nested while loop computing triangular number - issues David Kleinecke <dkleinecke@gmail.com> - 2015-07-11 10:51 -0700
Re: nested while loop computing triangular number - issues Keith Thompson <kst-u@mib.org> - 2015-07-11 14:56 -0700
Re: nested while loop computing triangular number - issues David Kleinecke <dkleinecke@gmail.com> - 2015-07-12 09:32 -0700
Re: nested while loop computing triangular number - issues James Kuyper <jameskuyper@verizon.net> - 2015-07-12 13:19 -0400
Re: nested while loop computing triangular number - issues David Kleinecke <dkleinecke@gmail.com> - 2015-07-13 10:16 -0700
Re: nested while loop computing triangular number - issues Keith Thompson <kst-u@mib.org> - 2015-07-12 11:48 -0700
Re: nested while loop computing triangular number - issues James Kuyper <jameskuyper@verizon.net> - 2015-07-12 15:23 -0400
Re: nested while loop computing triangular number - issues Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-15 11:02 -0700
Re: nested while loop computing triangular number - issues Keith Thompson <kst-u@mib.org> - 2015-07-15 13:19 -0700
Re: nested while loop computing triangular number - issues Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-20 11:01 -0700
Re: nested while loop computing triangular number - issues Alla _ <modelling.data@gmail.com> - 2015-07-11 08:45 -0700
csiph-web