[Gc] returning stack address without a warning

Eric Deplagne Eric.Deplagne at wanadoo.fr
Thu Oct 26 00:13:58 PDT 2006

> My goal with -Wall and similar is to at least document any remaining
> warnings in the source.  The collector inherently does a few things that
> should generate warnings in "normal" code, e.g. it returns the address
> of a local to get an upper bound on the stack pointer.  This also really
> applies only to gc7.

If there's nothing clever I didn't notice on the way, using an helper
function is enough to prevent the compiler from noticing what we're doing
to that poor local variable...

#include <stdio.h>

void *stackptr_v1(void)
  char p;

  /* this warns about returning the address of a local variable */
  return (void *)&p;

void *stackptr_v2_helper(void *p)
  return p;

void *stackptr_v2(void)
  char p;

  /* this should not warn */
  return stackptr_v2_helper(&p);

int main(void)
  /* should give twice the same value */

  return 0;

  Eric Deplagne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : https://napali.hpl.hp.com/pipermail/gc/attachments/20061026/4b7b7693/attachment.pgp

More information about the Gc mailing list