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


Groups > comp.lang.c > #66033

Re: nested while loop computing triangular number - issues

From Tim Rentsch <txr@alumni.caltech.edu>
Newsgroups comp.lang.c
Subject Re: nested while loop computing triangular number - issues
Date 2015-07-20 11:01 -0700
Organization A noiseless patient Spider
Message-ID <kfnpp3mlndg.fsf@x-alumni2.alumni.caltech.edu> (permalink)
References (3 earlier) <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> <lnd1ztjhqv.fsf@kst-u.example.com>

Show all headers | View raw


Keith Thompson <kst-u@mib.org> writes:

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

I see.  So there are (or at least probably are) some
plausible use cases, even if we can't think of one
right at the moment.

Despite that I still think that the utility is sufficiently
small so that there is no reason to add a new construct
to the language, since the cost of declaring a static
variable is pretty small, and even could be seen as a benefit,
forcing a name to be chosen for the value in question.

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


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