Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: nested while loop computing triangular number - issues |
| Date | 2015-07-12 13:19 -0400 |
| Organization | Self |
| Message-ID | <55A2A1AF.8030406@verizon.net> (permalink) |
| References | <8e9f29f8-a7d0-42c4-a146-2a0d0b937051@googlegroups.com> <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> |
On 07/12/2015 12:32 PM, David Kleinecke wrote:
> 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?
It's a special case use of feature with more general application. A
compound literal (6.5.2.5) has the form (type-name) {initializer-list},
and it creates a temporary unnamed object of the named type, initialized
using initializer list. In the general case, without the type-name, the
compiler would have no way of determining which type of object should be
initialized with those initializers. Keith's version of your code is
functionally equivalent to
struct foo _unnamed_temporary = {1, 0, 1, 0};
local_variables = _unnamed_temporary;
Note that while, in principle, this implies that storage is reserved for
two different struct foo objects, local_variables and
_unnamed_temporary, in practice a decent compiler could optimize the
extra storage away, since there's no way to refer to it after that line
of code is executed.
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