1 ) this works flawlessly, and as far as I know C and C++ have the same rules for scoping<br><br>#include <iostream><br><br>int main() {<br> {<br> int a = 42;<br> { std::cout << a << "\n"; }<br>
}<br> return (0);<br>}<br><br>also the C equivalent version works great too<br><br>#include <stdio.h><br><br>int main() {<br> {<br> int a = 42;<br> { printf("\n%d\n", a); }<br> }<br> return (0);<br>
}<br><br>So my point is: as far as the scoping rules are involved in this, they don't have any role in this error.<br><br>2 ) Why the external linkage of a var x should necessarily imply that the var x must be used or accessed in any way ?<br>
<br>In other words I can't see this strict relation and this constrain with an extern "C".<br><br><div class="gmail_quote">2013/7/29 SENTHIL KUMAR THANGAVELU <span dir="ltr"><<a href="mailto:senthil.t@samsung.com" target="_blank">senthil.t@samsung.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<p> </p>
<p>As I understand 2 potential issues could be here</p>
<p>1) 'a' maynot be visible to the second '{ }' block containing std::cout</p>
<p>2) Asking for extern "C" linkage for a stack variable, implying there is some C code which needs to see this stack variable</p>
<p> </p>
<p>------- <b>Original Message</b> -------</p>
<p><b>Sender</b> : Arji Cot<<a href="mailto:arjicot@gmail.com" target="_blank">arjicot@gmail.com</a>></p>
<p><b>Date</b> : Jul 29, 2013 19:26 (GMT+05:30)</p>
<p><b>Title</b> : [cfe-dev] Why this extern "C" fails ?</p><div class="im">
<p> </p><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><br><br><span style="FONT-FAMILY:courier new,monospace">--------------<br><br>this code fails to compile and the compiler message alone<br><br>main.cpp:5:12: error: expected unqualified-id<br>
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><br>There is something that I'm missing ?<br></span>
<p> </p>
<p> </p>
</div><p>Regards</p>
<p>Senthil Kumar</p>
<p> </p>
<p> </p>
<table>
<tbody>
<tr>
<td>
<p><img src="cid:QKNMBDIFBEI0@namo.co.kr" border="0" width="520"></p></td></tr></tbody></table></div><img src="" border="0" height="0" width="0"></blockquote></div><br>