Re: the same id in the same scope refers to different objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2017-09-04 at 10:33 +0100, Jonathan Wakely wrote:
> On 3 September 2017 at 11:43, Andrew Makhorin wrote:
> > Why x used to initialize y identifies not the same object as x used in
> > printf though x is the same identifier within the same block scope?
> 
> Because that's how scope and visibility works in the C programming
> language. A name is only in scope after it has been declared. Get a
> good book on C programming.
> 

Thank you for your reply.

I think the ISO C Standard is a good book. The subsection 6.2.1
"Scopes of identifiers" says:

   Different entities designated by the same identifier either have
   different scopes, or are in different name spaces.
   [...]
   Two identifiers have the same scope if and only if their scopes
   terminate at the same point.

In my example program x used in printf has block scope which overlaps
the file scope where other x is declared. Thus, the behavior of my
example program is undefined, because x is used to initialize y before
it is assigned an initial value (this is similar to the case when a
goto jumps into a block bypassing possible initialization of variables
declared within that block).





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux