public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* getting variables in order
@ 2003-09-27  6:10 Mike Johnson
  2003-09-27 12:37 ` Fabiano Ramos
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Johnson @ 2003-09-27  6:10 UTC (permalink / raw)
  To: gcc-help


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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: getting variables in order
  2003-09-27  6:10 getting variables in order Mike Johnson
@ 2003-09-27 12:37 ` Fabiano Ramos
  2003-09-27 15:51   ` Allen Williams
  0 siblings, 1 reply; 3+ messages in thread
From: Fabiano Ramos @ 2003-09-27 12:37 UTC (permalink / raw)
  To: gcc-help

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@bol.com.br>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: getting variables in order
  2003-09-27 12:37 ` Fabiano Ramos
@ 2003-09-27 15:51   ` Allen Williams
  0 siblings, 0 replies; 3+ messages in thread
From: Allen Williams @ 2003-09-27 15:51 UTC (permalink / raw)
  To: GCC Help

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 <fabramos@bol.com.br>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-09-27 15:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-27  6:10 getting variables in order Mike Johnson
2003-09-27 12:37 ` Fabiano Ramos
2003-09-27 15:51   ` Allen Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).