On Thu, 01 Jan 2015 17:51:45 +0000 novice2 via Digitalmars-d-learn <[email protected]> wrote:
> I want to use external or C function.
> It used only one time from one D function.
> I want do declare C function inside D function.
> I don't want to declare C function in global scope.
>
> Is my wish correct?
> Reduced code:
>
>
>
> extern (C) int getch();
> void main() {
> getch();
> }
> //compiled OK
>
>
>
> void main() {
> extern (C) int getch();
> getch();
> }
> //Error 42: Symbol Undefined __D4test4mainFZ5getchUZi
nope, you can't do this. actually, there is `pragma(mangle)`, but it's
not working for nested declarations. but you can use it to rename your
import:
pragma(mangle, "getch") extern (C) int external_getch();
void main() {
external_getch();
}
this will allow you to avoid name conflicts in your D code, yet still
link to external `getch` function.
signature.asc
Description: PGP signature
