Topic: a question about the example of 3.5 Program and linkage
Author: Ian <cfchou@gmail.com>
Date: Fri, 27 Apr 2007 12:25:23 CST Raw View
Thank you.
and what if the "int i;" on //2 does not exist,
Does the "extern int i;" on //3 receive linkage of "static int i;"
on //1?
Ian
On Apr 25, 3:21 am, gre...@pacbell.net (Greg Herlihy) wrote:
> On 4/23/07 9:55 PM, in article
> 1177241052.544636.314...@e65g2000hsc.googlegroups.com, "Ian"
>
> <cfc...@gmail.com> wrote:
> > I have a question about the example of 3.5 Program and linkage section
> > 6.
>
> > "......, and the object with static storage duration and external
> > linkage introduced by the declaration on line //3."
>
> > what i don't understand is what the object is. is the object declared
> > "static int i = 0; //1"?
>
> No, the i object at //3 does not match the i object declared at //1. And
> since the extern "i" declaration matches no other declaration within this
> file, it must refer to an "i" object defined in another translation unit.
>
> > if it is, then the object declared on //1(static, internal linkage)
> > and the object declared on //3 (external linkage) are refer to the
> > same one, right?
>
> No. The example shows that the two "i"'s refer to different objects because
> the first "i" is declared static - and therefore has internal linkage -
> while the other "i" is declared extern and therefore does not match the
> linkage of the first "i".
>
> > and how the code in other scopes refer to object declared on //3 ?
>
> They cannot. The purpose of the extern i declaration is to make the
> externally-defined i object visible within the scope in which the extern
> declaration appears.
>
> Greg
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-...@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: jg <jgu222@gmail.com>
Date: Mon, 7 May 2007 21:11:35 CST Raw View
===================================== MODERATOR'S COMMENT:
Apologies for the delay in moderation; this appears to be caused
by my ISP (Cox) dropping and/or blocking e-mail.
===================================== END OF MODERATOR'S COMMENT
On Apr 27, 11:25 am, Ian <cfc...@gmail.com> wrote:
> Thank you.
>
> and what if the "int i;" on //2 does not exist,
> Does the "extern int i;" on //3 receive linkage of "static int i;"
> on //1?
>
I think so. And they(//3 and //1) are the same object.
By the way, even with //2, I would like 'extern int i' on //3 to
refer to the same object as "static int i" on //1. In doing so,
we will have a simple one-definition rule (for objects with
linkage). Not sure why C++ standard defines them to
be different. Any comments ?
JG
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Ian <cfchou@gmail.com>
Date: Mon, 23 Apr 2007 22:55:37 CST Raw View
Hi all,
I have a question about the example of 3.5 Program and linkage section
6.
"......, and the object with static storage duration and external
linkage introduced by the declaration on line //3."
what i don't understand is what the object is. is the object declared
"static int i = 0; //1"?
if it is, then the object declared on //1(static, internal linkage)
and the object declared on //3 (external linkage) are refer to the
same one, right?
and how the code in other scopes refer to object declared on //3 ?
thank you!
Ian
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: greghe@pacbell.net (Greg Herlihy)
Date: Tue, 24 Apr 2007 19:21:06 GMT Raw View
On 4/23/07 9:55 PM, in article
1177241052.544636.314940@e65g2000hsc.googlegroups.com, "Ian"
<cfchou@gmail.com> wrote:
> I have a question about the example of 3.5 Program and linkage section
> 6.
>
> "......, and the object with static storage duration and external
> linkage introduced by the declaration on line //3."
>
> what i don't understand is what the object is. is the object declared
> "static int i = 0; //1"?
No, the i object at //3 does not match the i object declared at //1. And
since the extern "i" declaration matches no other declaration within this
file, it must refer to an "i" object defined in another translation unit.
> if it is, then the object declared on //1(static, internal linkage)
> and the object declared on //3 (external linkage) are refer to the
> same one, right?
No. The example shows that the two "i"'s refer to different objects because
the first "i" is declared static - and therefore has internal linkage -
while the other "i" is declared extern and therefore does not match the
linkage of the first "i".
> and how the code in other scopes refer to object declared on //3 ?
They cannot. The purpose of the extern i declaration is to make the
externally-defined i object visible within the scope in which the extern
declaration appears.
Greg
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: kuyper@wizard.net
Date: Tue, 24 Apr 2007 15:32:18 CST Raw View
Ian wrote:
> Hi all,
> I have a question about the example of 3.5 Program and linkage section
> 6.
>
> "......, and the object with static storage duration and external
> linkage introduced by the declaration on line //3."
>
> what i don't understand is what the object is. is the object declared
> "static int i = 0; //1"?
No, it's a seperate object from that one.
.
> and how the code in other scopes refer to object declared on //3 ?
They must declare it with their own 'extern int i' declaration.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]