我是学计算机科学的大四学生,以前从未见过如此奇怪的行为.我肯定有一些C语言的复杂性我不理解,但我现在完全不知所措.
我实现了以下功能:
Declaration
void parse_resp(unsigned char *resp, unsigned char *chunk, unsigned int *opcode, unsigned char *opparams, unsigned int *nonce, unsigned char *treasure, int *offset);
Basically just a function where I pass a punch of pointers to get populated
Definition
void parse_resp(unsigned char *resp, unsigned char *chunk, unsigned int *opcode, unsigned char *opparams, unsigned int *nonce, unsigned char *treasure, int *offset)
{
int chunklen = resp[0];
memcpy(&chunk[0], &resp[1], chunklen);
memcpy(opcode, &resp[chunklen + 1], 1);
memcpy(&opparams[0], &resp[chunklen + 2], 2);
memcpy(nonce, &resp[chunklen + 4], 4);
*nonce = htonl(*nonce);
}
Variable Initialization
unsigned char treasure[1024];
int offset = 0;
unsigned char chunk[127];
unsigned int opcode;
unsigned char opparams[2];
unsigned int nonce;
但这就是奇怪的地方.
Note:我知道这个错误有相当简单的解决方法,但我想先了解一下发生了什么.