www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - extern(C) declaration inside function

reply =?UTF-8?B?Ikx1w61z?= Marques" <luis luismarques.eu> writes:
When you declare an extern(C) function inside a D function it 
seems to continue to use D's name mangling, which is unexpected 
for me. For instance:

     void main()
     {
         extern(C) void foo(int);
         foo(42);
     }

     Undefined symbols for architecture x86_64:
       "__D4test4mainFZv3fooUiZv", referenced from:
             __Dmain in test.o

Is this a bug?
Sep 10 2013
next sibling parent reply =?UTF-8?B?Ikx1w61z?= Marques" <luis luismarques.eu> writes:
On Tuesday, 10 September 2013 at 13:41:14 UTC, Luís Marques wrote:
 Is this a bug?
*bump*
Sep 12 2013
parent "deadalnix" <deadalnix gmail.com> writes:
On Friday, 13 September 2013 at 02:46:22 UTC, Luís Marques wrote:
 On Tuesday, 10 September 2013 at 13:41:14 UTC, Luís Marques 
 wrote:
 Is this a bug?
*bump*
This is invalid in C, so not manglable. when you use extern C in this context, you mean calling convention.
Sep 12 2013
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 9/10/13, <luis luismarques.eu>" puremagic.com <"\"Lu=EDs".Marques"> wrot=
e:
 When you declare an extern(C) function inside a D function it
 seems to continue to use D's name mangling, which is unexpected
 for me. For instance:

      void main()
      {
          extern(C) void foo(int);
          foo(42);
      }
I was going to suggest using pragma(mangle, "...") as a workaround (using a git-head compiler), but actually it won't work here because this pragma can only be used in module-scope. Apparently there's a difference between a pragma declaration and pragma statement, I'm not sure why we have this split.
Sep 13 2013