static:
用在函数这一级,表示该函数只对本文件可见
用在函数内部,表示该变量的值在各个调用间一直保持延续性
#include <stdio.h>
int flag = 0;
void find_stack_direction(void)
{
static char *addr = NULL;
char dummy;
if(addr == NULL){
addr = &dummy;
find_stack_direction();
}
else{
(addr > &dummy) ? (flag = -1) : (flag = 1);
}
}
int main(int argc, char **argv)
{
find_stack_direction();
if(flag == 1){
printf("stack grew upward\n");
}
else{
printf("stack grew downward\n");
}
return 0;
}
|
阅读(951) | 评论(0) | 转发(0) |