Path: utzoo!attcan!uunet!wuarchive!cs.utexas.edu!rutgers!netnews.upenn.edu!grad2.cis.upenn.edu!kozak From: kozak@grad2.cis.upenn.edu (Chuck Kozak) Newsgroups: comp.lang.c Subject: accessing initial common structure members Keywords: ANSI Message-ID: <31468@netnews.upenn.edu> Date: 21 Oct 90 00:08:43 GMT Sender: news@netnews.upenn.edu Reply-To: kozak@grad1.cis.upenn.edu (Chuck Kozak) Organization: University of Pennsylvania Lines: 45 I have seen code where the first N members of different structures are accessed by code that treats the structures as identical. I looked through K&R II to check whether this practice is legal and cannot find any mention of it. This practice works with GNU C on a SUN-4 and I cannot think of a reason why it would not work on other architectures, but I would like to know whether it is a safe or bad practice. An example of what I mean is given below. struct common { struct common *next; struct common *prev; int type; }; struct type_1 { struct common *next; struct common *prev; int type; ... type_1 specific members ... }; struct type_2 { struct common *next; struct common *prev; int type; ... type_2 specific members ... }; void common_function(struct common *pnt) { ... access the next, prev, and type members ... } ... other code ... struct type_1 type_1_data; common_function((struct common *) &type_1_data); ... thanks for your help, Chuck Kozak kozak@grad2.cis.upenn.edu