Detect direction of stack growth
From: Adam Warner (usenet_at_consulting.net.nz)
Date: 12/27/04
- Next message: Phlip: "Re: Job Prospects for Software Engineers"
- Previous message: Emmanuel Delahaye: "Re: is NULL-checking redundant in accessor-functions?"
- Next in thread: Keith Thompson: "Re: Detect direction of stack growth"
- Reply: Keith Thompson: "Re: Detect direction of stack growth"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 27 Dec 2004 14:47:24 +1300
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
- Next message: Phlip: "Re: Job Prospects for Software Engineers"
- Previous message: Emmanuel Delahaye: "Re: is NULL-checking redundant in accessor-functions?"
- Next in thread: Keith Thompson: "Re: Detect direction of stack growth"
- Reply: Keith Thompson: "Re: Detect direction of stack growth"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
Loading