Scoped external function declaration

Daniel Kozak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 1 11:34:22 PST 2015


On Thursday, 1 January 2015 at 17:51:46 UTC, novice2 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

you can use local import


cfun.d:
module cfun;
extern (C) int getc();

main.d:
module main;
void main() {
     import cfun;
     getc();
}


More information about the Digitalmars-d-learn mailing list