ddraw: Assign to structs instead of using memcpy

Andrew Talbot Andrew.Talbot at talbotville.com
Tue Feb 19 16:42:14 CST 2008

Stefan Dösinger wrote:

> Am Sonntag, 17. Februar 2008 01:38:50 schrieb Andrew Talbot:
>> And I presume that if the underlying struct tags
>> are different between two similar types, then the compiler would warn of
>> type incompatibility if such an assignment were attempted.
> Not quite. You can have a DDSURFACEDESC2 *ddsd pointer, with ddsd->dwSize
> == sizeof(DDSURFACEDESC). Then you have in binary a DDSURFACEDESC *, not a
> DDSURFACEDESC2 *. The compiler won't see that, since the type is
> determined at runtime.
> (Don't blame me, Microsoft invented that)

Hi Stefan,

I am probably losing the plot, but thank you for your patience and I am
always glad to be put straight. My thinking is as follows.

If I apply the following patch:

diff --git a/dlls/ddraw/ddraw_thunks.c b/dlls/ddraw/ddraw_thunks.c
index b748ad4..57210a5 100644
--- a/dlls/ddraw/ddraw_thunks.c
+++ b/dlls/ddraw/ddraw_thunks.c
@@ -615,7 +615,7 @@ EnumDisplayModesCallbackThunk(LPDDSURFACEDESC2 pDDSD2,
LPVOID context)
     struct displaymodescallback_context *cbcontext = context;
-    memcpy(&DDSD,pDDSD2,sizeof(DDSD));
+    DDSD = *pDDSD2;
     DDSD.dwSize = sizeof(DDSD);
     return cbcontext->func(&DDSD, cbcontext->context);

I get this from the compiler (doing "make clean && make"):

ddraw_thunks.c: In function ?EnumDisplayModesCallbackThunk?:
ddraw_thunks.c:618: error: incompatible types in assignment
make: *** [ddraw_thunks.o] Error 1

I reason that the compiler throws this error because a DDSURFACEDESC is a
type based on a struct _DDSURFACEDESC, and a DDSURFACEDESC2 is one based on
a struct _DDSURFACEDESC2. So, regardless of size issues, the compiler will
not let me assign between two derived types that are not both aliases for a
common base type. One beauty of assignment over bit copying is the type
checking one gains. Am I missing the point?



More information about the wine-devel mailing list