Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!dptechno!dptechno.uucp From: dave@dptechno.uucp (Dave Lee) Newsgroups: comp.lang.c Subject: Structure and Array equivalence Message-ID: <582@dptechno.UUCP> Date: 15 Sep 90 00:20:43 GMT Sender: dave@dptechno.UUCP Organization: D.P. Technology Corp. Camarillo California Lines: 62 How portable is the following: Assume TYPE is any basic type (char,short,int,double,float ...) Assume N is a constant > 0 struct A_STRUCT { TYPE T1,T2,T3,T4,T5 .... TN; } A ; TYPE B[N]; TYPE C; funcA( X ) A_STRUCT *X; { X->T3 = C; } funcB( X ) TYPE *X; { X[2] = C ; } main() { funcA( &A ); funcB( (TYPE *) &A ); /**** OR ******/ funcA( (A_STRUCT) B ); funcB( B ); } ------- Q: Are funcA() and funcB() GUARENTEED to do the same thing ? Restated: If you have a structure which contains members of only one type, and you have an array of the same type with the same number of elements, is the compiler guarenteed to place the members in the same offsets in both the array and structure ? The particular case I am interested is with double, and int, but the general question is the same. Does the standard differ with K&R and ANSI ? All implementations I have ever seen work this way, but is this just luck ? EMail or Post as convient. Thank you . -- Dave Lee uunet!dptechno!dave