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


Groups > comp.lang.c > #65444

Re: nested while loop computing triangular number - issues

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: nested while loop computing triangular number - issues
Date 2015-07-12 15:23 -0400
Organization Self
Message-ID <55A2BE9E.1020707@verizon.net> (permalink)
References (1 earlier) <87si8uu5tr.fsf@bsb.me.uk> <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>

Show all headers | View raw


On 07/12/2015 02:48 PM, Keith Thompson wrote:
> David Kleinecke <dkleinecke@gmail.com> writes:
>> On Saturday, July 11, 2015 at 2:56:52 PM UTC-7, Keith Thompson wrote:
>>> David Kleinecke <dkleinecke@gmail.com> writes:
...
>>>> Given compiler control I could extend C to allow an assignment (not an
>>>> initialization 
>>>>     local_variables = {1, 0, 1, 0,};
>>>> Maybe this ia already a known extension.
>>>
>>> It's not an extension; it's a standard language feature, starting with
>>> C99, called "compound literals".
>>>
>>>     local_variables = (struct foo){1, 0, 1, 0};
>>>
>>> (Note that "(struct foo)" is not a cast; it's part of the syntax of the
>>> compound literal.)
>>>
>>> Of course if you insist on sticking to C90 you don't get to use things
>>> like this.
>>  
>> I'll stay with C90. 
>>
>> That's an ugly syntax. Why is the non-cast necessary? What confict
>> is resolved?
> 
> The type is necessary because without it the type of {1, 0, 1, 0}
> would be indeterminate -- unless the type is inferred from the
> context, but C expressions in general don't work that way.  Enclosing
> the type in parentheses is, I presume, deliberately reminiscent of
> cast syntax, and the stuff between the braces is explicitly defined
> in the grammar as an initializer-list.  I don't disagree with your
> statement that it's an ugly syntax, but it doesn't bother me much.
> 
> What alternative syntax would you suggest?

He's already given it, at the top of the quoted material above:

>>>>     local_variables = {1, 0, 1, 0,};

Keep in mind that this is not alternative syntax for compound literals.
It's syntax currently allowed only in initialization, re-purposed for
assignment.

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