L
luser-ex-troll
Is there a way to replace the heap allocation
with stack allocation in the following function?
void Oroll() {
int i,j,n;
Object *a;
stackis2(integer,integer,roll);
j = pop.u.i;
n = pop.u.i;
j %= n; //eliminate bogus loops
(void)((a=calloc((size_t)n,sizeof *a))
||error("VMerror in roll"));
for(i=0;i<n;i++) a = pop;
if(j>0) {
for(i=j-1; i>=0; i--) push(a);
for(i=n-1; i>=j; i--) push(a);
} else { //j<0
for(i=n-1+j; i>=0; i--) push(a);
for(i=n-1; i>=n+j; i--) push(a);
}
free(a);
}
I have a vague memory of a function called
alloc() that would do this, but gcc doesn't
have it.
From something posted recently I got the
idea to try:
Object a[n];
But, of course, n doesn't contain the argument
yet during the declaration section. (I did try it:
Segfault).
Can I make a bogus function call to load values
on the stack (being careful not to call another
function while expecting them to be there)?
tia
lxt
ps.
great group. excellent people.
hope I'm not making enemies.
with stack allocation in the following function?
void Oroll() {
int i,j,n;
Object *a;
stackis2(integer,integer,roll);
j = pop.u.i;
n = pop.u.i;
j %= n; //eliminate bogus loops
(void)((a=calloc((size_t)n,sizeof *a))
||error("VMerror in roll"));
for(i=0;i<n;i++) a = pop;
if(j>0) {
for(i=j-1; i>=0; i--) push(a);
for(i=n-1; i>=j; i--) push(a);
} else { //j<0
for(i=n-1+j; i>=0; i--) push(a);
for(i=n-1; i>=n+j; i--) push(a);
}
free(a);
}
I have a vague memory of a function called
alloc() that would do this, but gcc doesn't
have it.
From something posted recently I got the
idea to try:
Object a[n];
But, of course, n doesn't contain the argument
yet during the declaration section. (I did try it:
Segfault).
Can I make a bogus function call to load values
on the stack (being careful not to call another
function while expecting them to be there)?
tia
lxt
ps.
great group. excellent people.
hope I'm not making enemies.