Hi, Am 02.02.20 um 08:44 schrieb aotto:
Hi, the following scenario has a "definition hole" in the "C" languagecode example: ------------------------- struct base { ... }; struct A { struct base obj; ... } aObj; struct B { struct base obj; ... } bObj; void method_base (struct base * hdl, ...); method_base(&aObj, ...) method_base(&bObj, ...) ------------------------ - a POINTER to "A" is also a valid POINTER to "base" - a POINTER to "B" is also a valid POINTER to "base"
No. The order of elements of structures in memory is implementation defined and not guaranteed to be the order of enumeration in the definition.
The ONLY valid and portable way to express the call is method_base(&aObj.obj, ...) method_base(&bObj.obj, ...)
- a POINTER to "base" is NOT a valid POINTER to "A" and "B"
of course not. It is a pointer to one element within a structure, not to the structure itself.
Just my 2 cents, Holger
