I
ike
Could you please give your opinion on the portability of this code?
/* -------- begin findindex.c -------- */
struct Foo { int junk0; };
struct Bar { int junk1; struct Foo foo; int junk2; };
int findindex(struct Bar * bars, struct Foo * fooptr)
/* Pre:
* bars points to (the first element of) an array of Bar.
* fooptr points to the 'foo' member of an element of bars,
* i.e. fooptr == & bars.foo for some valid index i
* Returns:
* the actual value of i, as defined above.
*/
{
return ((char*)fooptr - (char*)&bars[0].foo) / sizeof *bars;
}
/* -------- end findindex.c -------- */
Ike
/* -------- begin findindex.c -------- */
struct Foo { int junk0; };
struct Bar { int junk1; struct Foo foo; int junk2; };
int findindex(struct Bar * bars, struct Foo * fooptr)
/* Pre:
* bars points to (the first element of) an array of Bar.
* fooptr points to the 'foo' member of an element of bars,
* i.e. fooptr == & bars.foo for some valid index i
* Returns:
* the actual value of i, as defined above.
*/
{
return ((char*)fooptr - (char*)&bars[0].foo) / sizeof *bars;
}
/* -------- end findindex.c -------- */
Ike