Passing opaque struct between functions/modules
Sarath Kumar
sarath at invalid.com
Wed Jan 23 08:33:06 PST 2013
DMD v2.61; openSUSE 12.1
Source:
-------
libA.d:
module libA;
extern (C)
{
struct Opaque;
Opaque* getObject();
void doSomething(Opaque *);
}
----------
libB.d:
module libB;
extern (C)
{
struct Opaque;
void doAction(Opaque *);
}
-----------
bug.d
import libA, libB;
int main(string[] args)
{
auto opaque = libA.getObject();
libA.doSomething(opaque); // this is okay
libB.doAction(opaque); // but this is not, compiler
error here
return 0;
}
When I compile the above files, I get the below error.
$ rdmd bug.d
bug.d(7): Error: function libB.doAction (Opaque*) is not callable
using argument types (Opaque*)
bug.d(7): Error: cannot implicitly convert expression (opaque) of
type Opaque* to Opaque*
If I do an explicit cast, libB.Opaque*, for opaque in line 7,
bug.d, I get completely different set of errors.
$ rdmd bug.d
libB.d(5): Error: struct libB.Opaque unknown size
libB.d(5): Error: struct libB.Opaque no size yet for forward
reference
libB.d(5): Error: struct libB.Opaque unknown size
libB.d(5): Error: struct libB.Opaque no size yet for forward
reference
libA.d(5): Error: struct libA.Opaque unknown size
libA.d(5): Error: struct libA.Opaque no size yet for forward
reference
Can someone please tell me the right way to pass an opaque object
between module's functions.
--
Thanks,
Sarath
More information about the Digitalmars-d-learn
mailing list