Re: struct versioning



Pres wrote:

Noticed that several windows API's take a size parameter.
i.e. one of the members of the struct is dwSize which is supposed
to be initialized by client code, by taking the sizeof of the struct.

I assume this is to enable versioning of structures

Yes.

To see a specific example, look up Microsoft's definition of the
BITMAPINFOHEADER, BITMAPV4HEADER, and BITMAPV5HEADER structures.

Is this fully standard compliant or are they taking liberties with their
close knowledge of the internals of the compiler.
Assume lib_v1 is compiled with compiler cl_v1 & lib_v2 is compiled
with compiler cl_v2, then it is safe to assume that sizeof(A_v1) would
be the same when compiled with different versions of the same compiler?

You have this part backwards. Compilers that claim to produce output
that works with Windows must be binary-compatible with Windows, not the
other way around.

Windows specifies the structure packing, the endianness, the sizes of
its primitive types (e.g. DWORD), and the calling conventions for any
code that calls or is called by any part of the Windows API.

- Ernie http://home.comcast.net/~erniew
.



Relevant Pages

  • Re: komplexes Problem mit Funktionszeigern
    ... Die Funktion gibt einen struct "by value" zurueck und bei der ... am Borland Compiler, da der Microsoft Compiler ... Man kann Argumente fuer eine Funktion z.B auf dem Stack uebergeben. ... Das funktioniert natuerlich nur fuer "Basis Typen" die in ein Register passen. ...
    (de.comp.lang.c)
  • Strange problem with linked list code on windows OS
    ... I see strange problem while I run the below code on Windows using gcc ... under cygwin on windows and gcc compiler on any Linux system. ... struct list_head name = LIST_INIT ...
    (comp.lang.c)
  • Re: Naming typedefs
    ... problem that a scalar could be returned in the A register ... to have waste precious cpu cycles copying the struct there ... of the hardware or twentieth century compiler technology. ... # to include the header defining it into every other header (assuming ...
    (comp.unix.programmer)
  • Re: assembly language and reverse engineering
    ... "return arguments to struct pointed to by register" and ... assumptions of CDECL-like conventions (also supports STDCALL, ... arg for handling struct return (slightly compiler, and compiler version, ...
    (alt.lang.asm)
  • Re: Nasty bug in the C# compiler, it truncates values on the stack
    ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... >> If you change the function Bug() and make bool b = true it works fine. ... >> compiler will always truncate the struct on the stack to 1 byte. ...
    (microsoft.public.dotnet.languages.csharp)