[cfe-dev] Why this extern "C" fails ?

Arji Cot arjicot at gmail.com
Thu Aug 1 05:42:52 PDT 2013


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.

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.

2013/7/30 Renato Golin <renato.golin at linaro.org>

> On 30 July 2013 09:08, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:
>
>> #include <iostream>
>>
>> int main() {
>>   {
>>     extern "C" int a = 42;
>>     { std::cout << a << "\n"; }
>>   }
>>   return (0);
>> }
>>
>> 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.
>>
>
> 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.
>
> 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.
>
> Honestly, you'd have more luck on dissecting the C++ standard at
> comp.lang.c++, not here.
>
> cheers,
> --renato
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130801/9ee8f21c/attachment.html>


More information about the cfe-dev mailing list