Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
March 21, 2003 C(/C++) interoperability | ||||
---|---|---|---|---|
| ||||
I know that one can declare something extern (C) to use a function written in C from within D source. I want to create a C function that can return (D-type) char[]. Is this possible? I presume it'll require some C include files for the D infrastructure ... All help gratefully received. Matthew |
March 21, 2003 Re: C(/C++) interoperability | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b5e2ar$2l47$1@digitaldaemon.com... > I know that one can declare something extern (C) to use a function written > in C from within D source. I want to create a C function that can return > (D-type) char[]. > > Is this possible? I presume it'll require some C include files for the D infrastructure ... > > All help gratefully received. All you need to do is return a struct that looks like this: struct Array { int length; void *data; }; |
March 21, 2003 Re: C(/C++) interoperability | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | allocated from where? "Walter" <walter@digitalmars.com> wrote in message news:b5eb13$2tuh$1@digitaldaemon.com... > > "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b5e2ar$2l47$1@digitaldaemon.com... > > I know that one can declare something extern (C) to use a function written > > in C from within D source. I want to create a C function that can return > > (D-type) char[]. > > > > Is this possible? I presume it'll require some C include files for the D infrastructure ... > > > > All help gratefully received. > > All you need to do is return a struct that looks like this: > > struct Array > { > int length; > void *data; > }; > > |
March 21, 2003 Re: C(/C++) interoperability | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | It's returned in the register pair EDX:EAX, so it doesn't matter where it is allocated. "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b5ehu2$3kd$1@digitaldaemon.com... > allocated from where? > > "Walter" <walter@digitalmars.com> wrote in message news:b5eb13$2tuh$1@digitaldaemon.com... > > > > "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b5e2ar$2l47$1@digitaldaemon.com... > > > I know that one can declare something extern (C) to use a function > written > > > in C from within D source. I want to create a C function that can return > > > (D-type) char[]. > > > > > > Is this possible? I presume it'll require some C include files for the D > > > infrastructure ... > > > > > > All help gratefully received. > > > > All you need to do is return a struct that looks like this: > > > > struct Array > > { > > int length; > > void *data; > > }; > > > > > > |
March 21, 2003 Re: C(/C++) interoperability | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote: > "Matthew Wilson" <dmd@synesis.com.au> wrote in message news:b5e2ar$2l47$1@digitaldaemon.com... > > I know that one can declare something extern (C) to use a function written > > in C from within D source. I want to create a C function that can return > > (D-type) char[]. > > > > Is this possible? I presume it'll require some C include files for the D infrastructure ... > > > > All help gratefully received. > > All you need to do is return a struct that looks like this: > > struct Array > { > int length; > void *data; > }; Walter, I know that yo ucan do this, but it is a very bad idea! This struct is not defined in the spec, so it totally depends on the implementation of the compiler. We need to define a standard way to do this, even if the standard is simply this. -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
March 21, 2003 Re: C(/C++) interoperability | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | Russ Lewis wrote:
> Walter, I know that yo ucan do this, but it is a very bad idea! This struct is
> not defined in the spec, so it totally depends on the implementation of the
> compiler. We need to define a standard way to do this, even if the standard is
> simply this.
It's the same with "%.*s" printf format - it relies upon this struct
just as well. So it can be considered as a part of specification.
It is even mentioned under "memory layout" in the spec.
-i.
|
Copyright © 1999-2021 by the D Language Foundation