Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site 3comvax.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!lll-crg!ucdavis!ucbvax!decvax!decwrl!Glacier!oliveb!3comvax!mikes From: mikes@3comvax.UUCP (Mike Shannon) Newsgroups: net.lang.c Subject: Re: Portability question Message-ID: <274@3comvax.UUCP> Date: Wed, 6-Nov-85 18:24:24 EST Article-I.D.: 3comvax.274 Posted: Wed Nov 6 18:24:24 1985 Date-Received: Sat, 9-Nov-85 07:08:12 EST References: <2834@brl-tgr.ARPA> Organization: 3Com Corp; Mountain View, CA Lines: 51 Paul Schauble in the cited article writes: > Could people please comment on the portability of this structure? If > it's not, why not and how does one set up a structure where one needs to > access the items both by pointer/subscript in a loop and by individual > name in inline code? > > struct x {something}; > struct x *ip; > > struct > { > struct x a; > struct x b; > struct x c; > struct x d; > struct x e; > } > index; > > y = index.a.whatever; > z = index.c.whatever; > > ip = (struct x *)&index; > ... > w = ip[i].whatever; Are you trying to drive us crazy? Why the !@*? would you ever want to give something two names??? Isn't life tough enough without this madness?? I'd bet that your basic problem is something like this: You have an array of seven structures, one for each day of the week. You often process these structures as an array, but sometimes, you want to just deal with one of them. And you'd like clear, mnemonic names to add the reader of your code. So, how about this: #define MONDAY 0 #define TUESDAY 1 ... #define SUNDAY 6 struct x a[SUNDAY + 1]; then you can do: for(i = Monday; i <= Sunday; i++) { a[i].whatever = something; } but you can also say: a[MONDAY].whatever = something; Thus it's readable, but you only have one name for a variable. -- Michael Shannon {ihnp4,hplabs}!oliveb!3comvax!mikes