<div dir="ltr"><div><div><div>Did not find the reference telling extern( May be need a thorough searching in the std. But quick search gave this <br>copy pasted from Section 7.1.1<br><br>6) The extern specifier can be applied only to the names of variables and functions. The extern specifier cannot<br>
be used in the declaration of class members or function parameters. For the linkage of a name declared with<br>an extern specifier, see 3.5. [ Note: The extern keyword can also be used in explicit-instantiations and<br>linkage-specifications, but it is not a storage-class-specifier in such contexts. — end note ]<br>
<br></div>So the usage <br><span style="font-family:courier new,monospace">extern "C" { int a = 42; }<br></span></div><span style="font-family:courier new,monospace">seems to be illegal as it is neither variable and function. <br>
<br></span></div><span style="font-family:courier new,monospace">But again, I am not C++ language specialist and not a compiler guy <br></span></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 30, 2013 at 11:14 AM, 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"><div class="im">"extern symbols should be in a global scope"<br><br></div>Can you provide a reference for this statement ?<div class="HOEnZb">
<div class="h5"><br><br><div class="gmail_quote">2013/7/29 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><div>On 29 July 2013 14:56, Arji Cot <span dir="ltr"><<a href="mailto:arjicot@gmail.com" target="_blank">arjicot@gmail.com</a>></span> wrote:<br>
</div></div><div class="gmail_extra"><div class="gmail_quote"><div>
<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"><span style="font-family:'courier new',monospace">--------------<br>
<br>#include <iostream><br><br>int main() {<br> {<br> extern "C" { int a = 42; }<br> { std::cout << a << "\n"; } <br>
}<br> return (0);<br>}</span></blockquote><div><br></div></div><div><div>Hi Arji,</div></div><div><br></div><div>As Olafur said, extern symbols should be in a global scope, and that "a" couldn't even be seen from the next line, and you'd see another error from the compiler if you removed the extern.</div>
<div>
<div><br></div><div><br></div><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"><span style="font-family:'courier new',monospace">main.cpp:5:12: error: expected unqualified-id</span><br>
<span style="font-family:'courier new',monospace">
extern "C" { int a = 42; }<br> ^<br>1 error generated.<br><br>It's not enough to me to explain why this is not working.<br></span></blockquote><div></div></div></div><br></div><div class="gmail_extra">
Every compiler error assumes familiarity with the language, at least enough to go and look at the definition of the terms involved in the error message (extern "C" in this case) in a book, on the web or the standard, which should give you enough information on how to fix the bug.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Compilers are famous for not giving enough information on error messages, and Clang stands out as being one of the best on that side, but no compiler will ever teach you the language via error messages.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">One rule of thumb is to use a different compiler and see if it also gives you an error, maybe a different error, or a better error message, or none at all. If you find that other compilers can handle your code and Clang cannot, maybe Clang is wrong (in which you should fill a bug), or maybe the other compiler is wrong at accepting your code, (in which you should file a bug in the other compiler). However, if the error is the same (which it is in GCC), than there's little you can ask the Clang community to do something.<br>
</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">As for learning C++, I suggest you buy Stroustroup's "The C++ Programming Language", read it cover to cover, and have it as your faithful companion for such cases, or use comp.lang.c++ for when you can't find the answer yourself, but Clang's list is really not the place for that level of discussion.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">cheers,</div><div class="gmail_extra">--renato</div></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><br clear="all"><br>-- <br><div dir="ltr"><div>Warm Regards<br>--Dev<br>OpenPegasus Developer/Committer<br><br><font size="5">(\__/)<br>(='.'=) This is Bunny. Copy and paste bunny<br>(")_(") to help him gain world domination.</font><br>
</div></div>
</div>