<div dir="ltr"><div><div><div>> nobody has offered a real explanation for this.<br><br></div>There have been plenty of explanations for this.<br><br></div>1. extern "C" must be in global scope, otherwise C can't call it since it doesn't know how to reference things defined within functions<br>
</div>2. Even if that worked, that variable is within another scope of the cout statement, so it's out of scope for the cout.<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 1, 2013 at 12:42 PM, Arji Cot <span dir="ltr"><<a href="mailto:arjicot@gmail.com" target="_blank">arjicot@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Well I was asking here on purpose because I figured out that it was the best thing to do, or in better terms, It was something that could have more chances to be explained by some compiler-guy rather than a programmer.<br>
<br>I'm not gonna use this in real code, it's just to test some business logic about how things works, notice that since now, nobody has offered a real explanation for this.<div class="HOEnZb"><div class="h5"><br>
<br><div class="gmail_quote">2013/7/30 Renato Golin <span dir="ltr"><<a href="mailto:renato.golin@linaro.org" target="_blank">renato.golin@linaro.org</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>On 30 July 2013 09:08, David Chisnall <span dir="ltr"><<a href="mailto:David.Chisnall@cl.cam.ac.uk" target="_blank">David.Chisnall@cl.cam.ac.uk</a>></span> wrote:<br>
<div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>#include <iostream><br></div><div>
<br>
int main() {<br>
{<br>
extern "C" int a = 42;<br>
{ std::cout << a << "\n"; }<br>
}<br>
return (0);<br>
}<br>
<br>
</div>This also fails to compile. I'm not sure what you'd expect the semantics to be. The variable a has automatic storage, and so a linkage specifier makes no sense in this context.<br></blockquote><div></div>
</div><br></div></div><div class="gmail_extra">This code fails to compile because: "variable declarations with the extern specifier at block scope refer to declarations that are members of an enclosing namespace, but they do not introduce new names into that scope." 3.3.2-10.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Ajit, your example contains several invalid C/C++ semantics, I'm really not sure how you got this code, or why you want to change the linkage semantics of a local variable.</div>
<div><br></div><div>Honestly, you'd have more luck on dissecting the C++ standard at comp.lang.c++, not here.</div><div><br></div><div>cheers,</div><div>--renato</div></div>
</blockquote></div><br>
</div></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>