【发布时间】:2018-03-09 20:53:39
【问题描述】:
#ifndef _LIST_H
#define _LIST_H
typedef int element_type;
typedef struct node * p_node;
typedef p_node list;
typedef struct node {
element_type e;
p_node next;
}node;
#endif
list list_append(list l, element_type n) {
p_node t = (p_node)malloc(sizeof(node));
if (!t) {
exit(1);
}
t->e = n;
while(l->next) {
l = l->next;
}
l->next = t;
return l;
}
#include <stdio.h>
#include "list.h"
int main() {
list l = list_init();
list_append(l,3);
return 0;
}
上面的c代码,它可以在gcc中运行,但不能在clang env中运行。 gcc 版本:4.4.7 20120313(红帽 4.4.7-18)(GCC) 铛: 配置: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM 版本 8.1.0 (clang-802.0.42) 目标:x86_64-apple-darwin16.4.0 线程模型:posix
当它在 clang env 中运行时,抛出 Segmentation fault: 11.
【问题讨论】: