zoukankan      html  css  js  c++  java
  • Embedded之Stack之三

    Stack Overflow

      While stacks are generally large, they don't occupy all of memory. It is possible to run out of stack space.

      For example, consider the code we had for factorial.  

    1   int fact( int n ) {
    2      if ( n == 0 )
    3         return 1 ;
    4      else
    5         return fact( n - 1 ) * n ;
    6    }

      Suppose fact(-1) is called. Then, the base case is never reached (well, it might be reached once we decrement so far that n wraps around to 0 again). This causes one stack frame after another to be pushed.

      Once the stack limit has been reached, we enter into invalid memory addresses, and the operating system takes over and kills your programming, telling you your program has a stack overflow.

      Probably the most common cause of stack overflow is a recursive function that doesn't hit the base case soon enough. For fans of recursion, this can be a problem, so just keep that in mind.

  • 相关阅读:
    udp tcp
    easy_install jinja2 mac linux
    linux 常用命令;
    Mac android 开发 sdk配置和手机连接
    ubuntu server 分区
    常见操作
    环境搭建相关
    ssh登录虚拟机上的linux
    算法学习
    转载一个 测试java类的玩意
  • 原文地址:https://www.cnblogs.com/mengdie/p/4487963.html
Copyright © 2011-2022 走看看