【发布时间】:2011-12-14 17:43:50
【问题描述】:
我今天遇到了一个奇怪的 C 问题。快速看一下这个简化的代码 sn-p:
typedef struct
{
/* The number of index terms */
int nTerms;
/* Information about each index term */
TERMINFO *terms;
} INDEX;
INDEX *buildIndex(char *termsfile, char *dirs[], int n, OPTIONS opts)
{
INDEX *ind = NULL;
ind->nTerms = 5;
return ind;
}
int main(int argc, char *argv[]) {
... // declare and assign values for TERMFILE, DIRS and opts.
INDEX *ind = buildIndex(TERMFILE, DIRS, sizeof(DIRS), opts); // LINE A
printf("Does NOT print %d\n",ind->nTerms); // LINE B
printf("Does NOT print as well"); // LINE C
return 0;
}
当我编译这个程序时,没有发生错误,但是当我运行编译后的文件时,它不会向命令行打印任何内容(我在 Windows 机器上使用 PuTTy)。把LINE A和LINE B这行去掉就更奇怪了,就可以打印LINE C了。
简而言之,LINE A 之后的任何内容都无法打印出来(或执行?)。
不知道我的代码有没有问题。
【问题讨论】:
-
你的第二个
LINE A是不是应该是LINE B? -
抱歉,有人帮我编辑了