0

我在编译我的代码时遇到一个无效的路径大小错误应用程序,但我自己找不到问题,有人可以帮忙吗?

/*********************************************************
* Node to represent a packet which includes a link reference*
* a link list of nodes with a pointer to a packet Struct    *

**********************************************************/
struct node {
unsigned int Source;
unsigned int Destination;
unsigned int Type;
int Port;
char *Data;
struct Packet *next;
 // Link to next packet

//unassigned int source
//unassigned int destination
//int type
//unassigned int port
//char *data
//struct node  *next link to next node
};

typedef struct Packet node; // Removes the need to constantly refer to struct


/*********************************************************
* Stubs to fully declared functions below                *
**********************************************************/
void Outpacket(node **head);
void push(node **head, node **aPacket);
node* pop(node **head);

int main() {

/*********************************************************
* pointers for the link list and the temporary packeyt to    *
* insert into the list                                   *
**********************************************************/
node *pPacket, *phead = NULL;

/*********************************************************
* Create a packet and also check the HEAP had room for it   *
**********************************************************/
pPacket = (node *)malloc(sizeof(node));
if (pPacket == NULL)
{
    printf("Error: Out of Memory\n");
    exit(1);
}

这只是完整代码的片段,但断点发生在以下行:

pPacket = (node *)malloc(sizeof(node));

谢谢你的帮助

4

2 回答 2

0

你为什么不使用构造:

typedef struct Packet { .... } node;

您命名了结构节点,但从类型指向其中的下一个元素

struct Packet *.

于 2013-04-25T11:13:53.670 回答
0

可能这是因为您使用struct Packet时没有定义它。

在您的定义中struct node,您正在使用struct Packet*. 但是没有什么叫struct Packed. 要么更改结构的名称,要么更改元素。

尝试以下操作:

struct Packet {
unsigned int Source;
unsigned int Destination;
unsigned int Type;
int Port;
char *Data;
struct Packet *next;
 // Link to next packet

//unassigned int source
//unassigned int destination
//int type
//unassigned int port
//char *data
//struct node  *next link to next node
};

typedef struct Packet node; // Removes the need to constantly refer to struct

在这里,struct Packetnode都是一样的结构,并没有异常。

于 2013-04-25T11:04:57.800 回答