【问题标题】:Segfault on Windows but not Linux (GDB info included) - CWindows 上的 Segfault 而非 Linux(包括 GDB 信息)- C
【发布时间】:2016-05-26 02:18:33
【问题描述】:

我在 Windows 中遇到了段错误,但在 Linux 中没有(相同的程序)。使用 GDB (minGW),我得到以下信息:

程序收到信号SIGSEGV,分段错误。 21 0x7c8024f0 在 ReleaseMutex() from C:\WINDOWS\system32\kernel32.dll

程序在 Linux 系统上运行完成。崩溃发生在此函数的递归调用期间:

    void recursive_paint_char(int x,int y,int **inimage,int new_color,int fore_color)
{

/* 
   This routine paints the connected object around the pixel x,y in image inimage
   to the color new_color. The foreground color is assumed to be fore_color.
*/
 int        i;
 int        xt,yt;

 inimage[x][y]=new_color;
 for (i=0;i<8;i++)
 {

  xt=x+xc[i];
  yt=y+yc[i];
  if (inimage[xt][yt]==fore_color) 
  {
    printf("this statement prints\n"); 
   recursive_paint_char(xt,yt,inimage,new_color,fore_color);
   printf("this statement never prints\n"); 
  }
 }
}

在出现段错误之前,递归大约进行了 171,000 次调用

【问题讨论】:

  • 我不能保证 linux 上没有内存泄漏,但程序确实可以处理大型数据集(50 组 ~100-200 张图像)
  • 假设每次调用在堆栈上大约有 48 个字节,那么 171000 次调用将占用大约 8MB 的堆栈。所以你的 linux 机器显然比你的 windows 机器设置了更大的堆栈。
  • 递归是尾递归没关系吗?
  • 尾调用必须是函数所做的最后一件事。在您的情况下,递归调用在循环内,因此不能作为尾调用实现。

标签: c pointers segmentation-fault


【解决方案1】:

user3386109 回答了问题 - 问题似乎是堆栈大小。

【讨论】:

    猜你喜欢
    • 2013-05-30
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    • 2018-06-30
    • 1970-01-01
    相关资源
    最近更新 更多