Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] Re: TODO
Home

[Freeciv-Dev] Re: TODO

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: TODO
From: Jeff Mallatt <jjm@xxxxxxxxxxxx>
Date: Fri, 22 Sep 2000 09:51:53 -0400

At 2000/09/22 09:23 , Jules Bean wrote:
>On Fri, Sep 22, 2000 at 08:15:39AM -0400, Jeff Mallatt wrote:
>> At 2000/09/22 06:49 , Jules Bean wrote:
>> >On Fri, Sep 22, 2000 at 12:45:45PM +0200, Raimar Falke wrote:
>> >> On Fri, Sep 22, 2000 at 10:56:58AM +0100, Jules Bean wrote:
>> >> > 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.
>> >
>> >Nope.
>> >
>> >The above will make another copy of 'l' and return that.
>> 
>> At risk of showing my age...  Raimar would be correct, if we were using
>> original K&R C.  But, since we require ANSI C, struct assignments and
>> returns work just fine.
>
>Surely it was never the case that structures were silently converted
>to pointers, rendering the above case dangerous?
>
>I thought that in K&R C returning a complex type was simply invalid,
>not dangerous..

Yes.  It was a compile-time error.

jjm




[Prev in Thread] Current Thread [Next in Thread]