[Freeciv-Dev] Re: TODO
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On 2000-09-22 12:45:45, Raimar Falke wrote:
> On Fri, Sep 22, 2000 at 10:56:58AM +0100, Jules Bean wrote:
> > On Fri, Sep 22, 2000 at 11:55:43AM +0200, Erik Sigra wrote:
> > > Falk Hueffner wrote:
> > > >
> > > > Erik Sigra <freeciv@xxxxxxx> writes:
> > > >
> > > > > Yes, my implementation requires a lot of recoding (I'm doing it
> > > > > right now). But it can be done in steps. It just takes some
> > > > > typecasting klugdes ("(struct locus({x, y}") in some places during
> > >
> > > Should have been "(struct locus){x, y}" of course.
> > >
> > > > > the transition.
> > > >
> > > > Please don't; this is not portable, it's a gcc extension.
> > >
> > > Really, I didn't know. Then how it is it done by ANSI?
> >
> > 'on-the-fly' struct creation is not possible.
> >
> > Instead use a 'constructor' function
> >
> > struct locus make_locus(int x,int y) {
> > struct locus l;
> > l.x=x; l.y=y;
> > return l;
> > }
>
> AFAIK this is wrong. The variable l is created on the stack which is
> destroyed at the return. You have to do return a newly allocated part of
> memory. Using this you will get some problems with bookkeeping since C has
> no GC.
That's true (unless this is some weird special case)
The easiest way to do it probably is to have a variable in the calling
context and have a function like:
struct locus *
set_locus( struct locus *l, int x, int y )
{
l->x = x;
l->y = y;
return l;
}
That way You don't have to worry about allocating memory and freeing it
later...
/Daniel
--
Now take a deep breath, smile and don't take life so seriously... :)
- [Freeciv-Dev] Re: TODO, (continued)
- [Freeciv-Dev] Re: TODO, Falk Hueffner, 2000/09/22
- [Freeciv-Dev] Re: TODO, Erik Sigra, 2000/09/22
- [Freeciv-Dev] Re: TODO, Jules Bean, 2000/09/22
- [Freeciv-Dev] Re: TODO, Raimar Falke, 2000/09/22
- [Freeciv-Dev] Re: TODO, Jules Bean, 2000/09/22
- [Freeciv-Dev] Re: TODO, Daniel Sjölie, 2000/09/22
- [Freeciv-Dev] Re: TODO, Jeff Mallatt, 2000/09/22
- [Freeciv-Dev] Re: TODO, Jules Bean, 2000/09/22
- [Freeciv-Dev] Re: TODO, Jeff Mallatt, 2000/09/22
- [Freeciv-Dev] Re: TODO, Raimar Falke, 2000/09/22
- [Freeciv-Dev] Re: TODO,
Daniel Sjölie <=
- [Freeciv-Dev] Re: TODO, Gaute B Strokkenes, 2000/09/22
- [Freeciv-Dev] Re: TODO, Greg Wooledge, 2000/09/22
- [Freeciv-Dev] Re: TODO, Gaute B Strokkenes, 2000/09/22
- [Freeciv-Dev] Re: TODO, Erik Sigra, 2000/09/22
- [Freeciv-Dev] Re: -ansi -pedantic, was Re: TODO, David Pfitzner, 2000/09/22
[Freeciv-Dev] Re: TODO, David Pfitzner, 2000/09/24
|
|