#include <windows.h>
#include <iostream.h>
#define A_LOT 256
int *
setup_values(void)
{
int values[A_LOT]; //Bug: This should be 'static', not automatic
for (int i=0; i < A_LOT; i++) {
values[i] = i;
}
return(values); //Bug: returning a value which vanishes as we return
}
int
main(int, char **)
{
int *values;
values = setup_values();
for (int i=0; i < A_LOT; i++) {
//BSR: the values from "setup_values" are no longer alive on the stack
cerr << "element #" << i << " is " << values[i] << '\n';
}
return(0);
}
(C) Copyright IBM Corporation 1992, 2010.