From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26567 invoked by alias); 27 Sep 2003 15:51:58 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 26560 invoked from network); 27 Sep 2003 15:51:57 -0000 Received: from unknown (HELO ms-smtp-01.tampabay.rr.com) (65.32.1.43) by sources.redhat.com with SMTP; 27 Sep 2003 15:51:57 -0000 Received: from csunadmin (123.66.35.65.cfl.rr.com [65.35.66.123]) by ms-smtp-01.tampabay.rr.com (8.12.5/8.12.5) with SMTP id h8RFpu9u012891 for ; Sat, 27 Sep 2003 11:51:56 -0400 (EDT) From: "Allen Williams" To: "GCC Help" Subject: RE: getting variables in order Date: Sat, 27 Sep 2003 15:51:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal Importance: Normal In-Reply-To: <1064666259.3469.6.camel@xp2200> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-SW-Source: 2003-09/txt/msg00304.txt.bz2 You could also put them in a struct: struct vars { char variables[17]; char *a; char *b; int *c; char *d; char *e; int *f; char *g; } varstruct, *pvarstruct; Now, you instantiate the structure and provide your users a pvarstruct to access it. My personal opinion is that this is the more appropriate way, since this one of the things structures were meant for- it's more in line with the form of the language. Note that on some OS's you might have to tell the compiler to pack the structure- using something like #pragma PACK. In spite of the language support, these sorts of things aren't the most portable code ever written. Depending on your application, I'd be much more inclined to use C++ and provide your users with access functions to the variables they need. Your mileage may vary! ---------- anw > -----Original Message----- > From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]On > Behalf Of Fabiano Ramos > Sent: Saturday, September 27, 2003 8:38 AM > To: gcc-help@gcc.gnu.org > Subject: Re: getting variables in order > > > Used an array instead. I do not know what is your machine, so you should > use sizeof o ensure portability, but I'll assume 1 byte chars and 4 byte > integers: > > char variables[17]; > char *a = &variables[0]; > char *b = &variables[1]; > int *c = &variables[2]; > char *d = &variables[6]; > char *e = &variables[7]; > int *f = &variables[12]; > char *g = &variables[16]; > > Fabiano > > On Sat, 2003-09-27 at 03:14, Mike Johnson wrote: > > I'd like to define a list of variables as so: > > > > char a; > > char b; > > int c; > > char d; > > char e[5]; > > int f; > > char g; > > > > and have them packed and in order in the map file. > > > > when I do this they are defined in some random order in the map > > file. > > > > This is so I can access them as a pointer offset from a to allow > > a user to query the state of the vars. > > > > I'm using the AVR version of GCC. > > > > Thanx for any ideas. > > > > Mike Johnson > > > > > -- > Fabiano Ramos