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

Ólafur Waage olafurw at gmail.com
Mon Jul 29 07:09:53 PDT 2013


This works fine, IIRC the extern must be in global scope.

#include <iostream>

extern "C" {
    int a = 42;
}

int main() {
  {
    { std::cout << a << "\n"; }
  }
  return (0);
}




On Mon, Jul 29, 2013 at 2:06 PM, Ólafur Waage <olafurw at gmail.com> wrote:

> What is your compile line?
>
>
> On Mon, Jul 29, 2013 at 1:56 PM, Arji Cot <arjicot at gmail.com> wrote:
>
>> --------------
>>
>> #include <iostream>
>>
>> int main() {
>>   {
>>     extern "C" { int a = 42; }
>>     { std::cout << a << "\n"; }
>>   }
>>   return (0);
>> }
>>
>> --------------
>>
>> this code fails to compile and the compiler message alone
>>
>> main.cpp:5:12: error: expected unqualified-id
>>     extern "C" { int a = 42; }
>>            ^
>> 1 error generated.
>>
>> It's not enough to me to explain why this is not working.
>>
>> There is something that I'm missing ?
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130729/03b1c81d/attachment.html>


More information about the cfe-dev mailing list