struct versioning



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

/* first version of struct */
typedef struct { int dwSize; type1 t1; } A;

/* 2nd version of struct in new version of the library */

typedef struct { int dwSize; type1 t1; } A_v1; // Old struct renamed to
A_v1
typedef struct { int dwSize; type1 t1; type 2;} A;


So their implementation of function will look like
// Impl in v1 of Lib
void fn(A * ptr) { /* Implementation */ }

//Impl in v2 of lib

void fn_v1(A_v1 * ptr) { /* Renamed old fn to fn_v1 - Implementation */

void fn(A * ptr)
{
if (ptr->dwSize == sizeof(A_v1)
{
fn_v1(); return;
}
/* New Implementation Below */

}

Is my assumption correct - is this something like what they would
be doing?

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?

i.e. can sizeof(A_v1) can when compiled with gcc v2 as compared to
gcc v1?
If it cannot, then can it change when compiled by two totally different
compilers?

Any other gotchas?


.



Relevant Pages

  • base libobjc on 5.4 p2
    ... the base gcc provide with 5.4#p2 is a 3.4.2. ... It seems this lib is only provide: ... options) to allow us to use the base compiler provide with FreeBSD. ... require to install a gcc port to have this features enables (and so, ...
    (freebsd-questions)
  • 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: 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)