www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/16/15:16:13

From: Ian Chapman <ichapman AT nortel DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: strange warning
Date: Mon, 16 Dec 1996 13:28:22 -0500
Organization: Nortel Technology
Lines: 35
Message-ID: <32B594C6.4799@nortel.ca>
References: <58vhpj$ors AT nntp DOT novia DOT net> <32B3F9CD DOT E2 AT cs DOT com>
NNTP-Posting-Host: bkanm382.bnr.ca
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

John M. Aldrich wrote:
> 
> Alaric Dailey wrote:
> >
> > context.c: In function `go_deep':
> > context.c:34 warning: function returns  address of local variable
> 
> Well, according to the function, this is a perfectly valid warning.
> Local automatic variables are by definition allocated from the stack,
> and reclaimed when the function returns.  So the address returned by the
> go_deep() function is meaningless, except in that it represents a
> section of the stack that is unused when the calling function sees it.

THIS IS DANGEROUS AS ANY FUTURE FUNCTIONCALLS WILL REUSE THIS PORTION 
OF THE STACK FOR RETURN ADDRESS AND LOCAL VARIABLES.
> 
> Since this appears to be what the function is used for (for whatever
> reason), you can probably ignore the warning without trouble.  There's
> no guarantee here, though, and I strongly suggest that you examine every
> piece of code that calls go_deep() to see if there isn't some better way
> to accomplish what it does.  I can't honestly see how this would
> actually help anything, and a simple call to alloca() from the caller
> function would return an address which is far more reliable in the
> current stack frame.
> 
> In a very basic sense, the program you are using is not ANSI C if it
> uses such code, because ANSI makes no guarantees about the way the stack
> is organized.
> 
> --
> ---------------------------------------------------------------------
> | John M. Aldrich, aka Fighteer I |        fighteer AT cs DOT com          |
> | Descent 2: The Infinite Abyss - The greatest Internet game of all |
> | time just got better!  This time, you're going all the way down...|
> ---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019