问题描述
如果我有一个很长的char数组[100],其中存储了一个结构列表,并且如果我想最后添加一个结构,该如何检查它是否超出边界?
例如,
static char arr[100];
typedef NODE* node_ptr;
typedef struct node
{
char a;
char b;
int size;
node_ptr next;
}NODE;
//arr already contains few node in it.
//size: the new node size,I want to add in the end
node_ptr add_node(node_ptr last,size_t size)
{
node_ptr new;
if(last+2*sizeof(NODE)+size<arr+100)
//add new node
return new;
}
如何检查新节点是否超出数组边界?