RE: getting variables in order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx]On
> Behalf Of Fabiano Ramos
> Sent: Saturday, September 27, 2003 8:38 AM
> To: gcc-help@xxxxxxxxxxx
> 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 <fabramos@xxxxxxxxxx>


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux