【发布时间】:2012-02-17 21:00:33
【问题描述】:
我在 Linux 系统上遇到了分段错误问题。 我正在使用 Aho 和 Ullman 的“计算机科学基础”C 版中的代码。 这是代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct que_element
{
long mem_address;
long mem_data;
int msg;
} Qq;
typedef struct CELL *LIST;
struct CELL
{
Qq el;
int element;
LIST next;
};
Qq l1element;
typedef struct
{
LIST front;
LIST rear;
} QUEUE;
main()
{
QUEUE *l1c2l1d; /*L1 Controller to L1 Data */
l1c2l1d->front = malloc(sizeof *l1c2l1d);
}
【问题讨论】:
-
如果要代表
true/false,请使用typedef char BOOLEAN。 ;)int通常在 32 位上有 4 个字节,而char总是有 1 个字节。 -
@Gandaro 但是 int 通常比
char访问更快。 -
为什么要定义自己的布尔值而不是包含stdbool.h?
标签: c segmentation-fault malloc