A
Adam Warner
Hi all,
Is this a (C99) portable way to detect whether the C stack grows upwards
(1) or downwards (-1)?
#include <stdio.h>
int stack_direction=0;
void detect_stack_direction(void * stack_start) {
void * stack_current;
stack_direction=-1;
if (&stack_start<&stack_current) stack_direction=1;
}
int main() {
void * stack_start;
detect_stack_direction(stack_start);
printf("Stack grows: %i\n", stack_direction);
return 0;
}
Thanks,
Adam
Is this a (C99) portable way to detect whether the C stack grows upwards
(1) or downwards (-1)?
#include <stdio.h>
int stack_direction=0;
void detect_stack_direction(void * stack_start) {
void * stack_current;
stack_direction=-1;
if (&stack_start<&stack_current) stack_direction=1;
}
int main() {
void * stack_start;
detect_stack_direction(stack_start);
printf("Stack grows: %i\n", stack_direction);
return 0;
}
Thanks,
Adam