Skip to content
Prev 46913 / 63424 Next

Compiler warning: function returns address of local variable

The message is certainly not "simply bogus".  Returning the address of
a local variable is almost always a bug.

In this case, there is no real bug in R-3.0.1, since the result is
used for the low-level, system-dependent operation of determining the
direction of stack growth, but this is a very rare use.  For the
compiler to issue such a warning is fully justified.

The warning could be avoided by using the approach taken in pqR, which
has the following routine in main.c:

  /* Detemine whether the stack grows down (+1) or up (-1).  Passed the
     address of a local variable in the caller's stack frame.
  
     This is put here, though called only from system.c, so that the compiler
     will not be able to inline it. */
  
  int R_stack_growth_direction (uintptr_t cvaraddr)
  {
      int dummy;
      return (uintptr_t) &dummy < cvaraddr ? 1 : -1;
  }