Extensions to types loaded from a C library
Jeremy DeHaan
dehaan.jeremiah at gmail.com
Fri Dec 14 01:30:49 PST 2012
I was playing with some code in the Derelict project(mainly the
SFML portion) and was wondering what would happen if I made some
changes.
Here's an example of what I mean.
In the C code, the struct sfVector2f is defined as such:
typedef struct
{
float x;
float y;
} sfVector2f;
The D version of this when loading the .dll into the application
would be like this:
struct sfVector2f
{
float x;
float y;
}
And to my understanding, defining this allows us to use this
structure in our calls to the C functions in the .dll. But then I
thought, "could I maybe make some things easier?" and proceeded
to experiment a bit. Right now I have the structure looking like
this:
struct sfVector2f
{
float x;
float y;
this(float X, float Y)
{
x = X;
y = Y;
}
}
This compiles just fine, and I can even use the constructor to
create the object with seemingly no problems. But is this safe to
do? My gut tells me yes, but I would rather make sure before I
cause something to explode unknowingly!
More information about the Digitalmars-d-learn
mailing list