Oracle® Solaris Studio 12.4:C 用户指南

退出打印视图

更新时间: 2014 年 12 月
 
 

8.2.4 步骤 4:编辑代码

在开窗口终端上,可能具有多个任意大小的窗口。可能由于在行过少的窗口中运行 prog 而出现错误消息 "out of storage"。换句话说,可能属于使用负数调用 mymalloc() 的情况之一。现在您要注意,将来程序在这种情况下异常终止时,在打印更有意义的错误消息 "screen too small" 之后,它会显示上述消息。按以下方式编辑函数 dispinit()

cscope 函数: 纠正问题:

void
dispinit()
{
/* calculate the maximum displayed reference lines */
    lastdispline = FLDLINE - 4;
    mdisprefs = lastdispline - REFLINE + 1;
    if (mdisprefs > 9) {
       mdisprefs = 9;
    }
/* allocate the displayed line array */
    displine = (int *) mymalloc(mdisprefs * sizeof(int));
}
^L/* display a page of the references */

void
display()
{
    char file[PATHLEN + 1]; /* file name */
    char function[PATHLEN + 1];/* function name */
    char linenum[NUMLEN + 1]; /* line number */
    int screenline; /* screen line number */
    int width; /* source line display width */
    register int i, j;
"display.c" 622 lines, 14326 characters

您已纠正我们在本节开始时讨论的问题。现在,如果 prog 在行过少的窗口中运行,它不会简单地以无启示性的错误消息 "out of storage" 而失败。而是会在退出之前检查窗口大小并生成更富有意义的错误消息。