Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Shao Miller <sha0.miller@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: is this legal (and ANSI89 conforming) C? |
| Date | 2011-06-23 08:28 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <itvbkd$877$1@dont-email.me> (permalink) |
| References | <8c8776b8-c626-474f-9c92-5806bd1a7bd3@u26g2000vby.googlegroups.com> <e1ad377b-bf48-4f0d-a943-f8ceb899f3d5@d14g2000yqb.googlegroups.com> <itu6jh$396$1@dont-email.me> <ituhnb$omh$1@dont-email.me> <0.73ee48583a277b561b4d.20110623114743BST.87iprwbz8w.fsf@bsb.me.uk> |
On 6/23/2011 06:47, Ben Bacarisse wrote:
> Shao Miller<sha0.miller@gmail.com> writes:
>
>> On 6/22/2011 8:57 PM, Eric Sosman wrote:
>>> On 6/22/2011 2:35 PM, Tom St Denis wrote:
>>>> On Jun 22, 1:26 pm, "dr.oktopus"<blindwi...@freeonline.zzn.com>
>>>> wrote:
>>>>> Hello,
>>>>> suppose that I have to create a dummy node of a list data type
>>>>> that references itself (like in Sedgewick book). Is this:
>>>>>
>>>>> struct node {
>>>>> struct node *next;
>>>>> int c;
>>>>>
>>>>> } dummy_node = {&dummy_node };
>>>>>
>>>>> legal? I think no problem should be, but I want a confirm.
>>>>
>>>> IIRC it's valid because once you declare the variable you can use it
>>>> right away.
>>>
>>> Yes. The scope of the identifier `node' begins immediately
>>> after its first appearance, so it's in scope when mentioned on
>>> the next line. The scope of the identifier `dummy_node' begins
>>> immediately after its declarator (that is, just before the `='),
>>> so it's in scope when used in the initializer.
>>>
>>
>> I could be mistaken, but for C89:
>>
>> - I believe that an initializer for a 'struct', 'union', or array must
>> be a constant expression.
>>
>> - I believe that '&dummy_node' is not an address constant because
>> dummy_node' is not an object with 'static' storage duration.
>
> You don't know it doesn't! The code is, presumably, intended to be at
> file scope (if I can mix usages for a moment) so 'dummy_node' will be an
> object with static storage duration.
>
"Create" and "dummy_node" give me the impression that it is within a
function. As always, I could be mistaken. Perhaps dr.oktopus could
clarify?
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
is this legal (and ANSI89 conforming) C? "dr.oktopus" <blindwilly@freeonline.zzn.com> - 2011-06-22 10:26 -0700
Re: is this legal (and ANSI89 conforming) C? Tom St Denis <tom@iahu.ca> - 2011-06-22 11:35 -0700
Re: is this legal (and ANSI89 conforming) C? BGB <cr88192@hotmail.com> - 2011-06-22 12:49 -0700
Re: is this legal (and ANSI89 conforming) C? Angel <angel+news@spamcop.net> - 2011-06-22 20:00 +0000
Re: is this legal (and ANSI89 conforming) C? Tom St Denis <tom@iahu.ca> - 2011-06-22 13:39 -0700
Re: is this legal (and ANSI89 conforming) C? BGB <cr88192@hotmail.com> - 2011-06-22 15:22 -0700
Re: is this legal (and ANSI89 conforming) C? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-22 21:57 -0400
Re: is this legal (and ANSI89 conforming) C? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-06-23 11:47 +0100
Re: is this legal (and ANSI89 conforming) C? Shao Miller <sha0.miller@gmail.com> - 2011-06-23 08:28 -0400
Re: is this legal (and ANSI89 conforming) C? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-06-23 14:08 +0100
Re: is this legal (and ANSI89 conforming) C? "dr.oktopus" <blindwilly@freeonline.zzn.com> - 2011-06-24 12:36 -0700
Re: is this legal (and ANSI89 conforming) C? Shao Miller <sha0.miller@gmail.com> - 2011-06-24 16:01 -0400
Re: is this legal (and ANSI89 conforming) C? "dr.oktopus" <blindwilly@freeonline.zzn.com> - 2011-06-25 13:08 -0700
Re: is this legal (and ANSI89 conforming) C? James Kuyper <jameskuyper@verizon.net> - 2011-06-25 19:02 -0400
Re: is this legal (and ANSI89 conforming) C? Shao Miller <sha0.miller@gmail.com> - 2011-06-22 19:24 -0500
Re: is this legal (and ANSI89 conforming) C? Shao Miller <sha0.miller@gmail.com> - 2011-06-22 19:34 -0500
Re: is this legal (and ANSI89 conforming) C? Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-23 01:15 -0700
Re: is this legal (and ANSI89 conforming) C? James Kuyper <jameskuyper@verizon.net> - 2011-06-23 06:15 -0400
csiph-web