Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Feb 2001 09:42:29 -0600
From:      "Jacques A. Vidrine" <n@nectar.com>
To:        freebsd-hackers@freebsd.org
Subject:   portability sanity check
Message-ID:  <20010221094228.A93221@hamlet.nectar.com>

next in thread | raw e-mail | index | archive | help
Is the following portable and safe?

Given n different structure declarations, where each structure begins
with the same member type, can any instance of any of the structures
be cast to the (pointer) type of the first member?

e.g.

   struct foo {
       const char *s;
       ...
   };

   struct bar {
       const char *s;
       ...
   };

   int gefahr(struct foo *Foo, struct bar *Bar) {
       return strcmp((const char *s)Foo, (const char *s)Bar);
   }

Likewise if the first member were a more complex data type, but
nevertheless the same between the different structures.

It seems safe to me, but I can't explain why :-)

Cheers,
-- 
Jacques Vidrine / n@nectar.com / jvidrine@verio.net / nectar@FreeBSD.org

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010221094228.A93221>