我正在嘗試使用XCode並嘗試編譯別人的Windows代碼。爲什麼我會得到「使用未聲明的標識符'malloc'」?
有這樣的:
inline GMVariable(const char* a) {
unsigned int len = strlen(a);
char *data = (char*)(malloc(len+13));
if(data==NULL) {
}
// Apparently the first two bytes are the code page (0xfde9 = UTF8)
// and the next two bytes are the number of bytes per character (1).
// But it also works if you just set it to 0, apparently.
// This is little-endian, so the two first bytes actually go last.
*(unsigned int*)(data) = 0x0001fde9;
// This is the reference count. I just set it to a high value
// so GM doesn't try to free the memory.
*(unsigned int*)(data+4) = 1000;
// Finally, the length of the string.
*(unsigned int*)(data+8) = len;
memcpy(data+12, a, len+1);
type = 1;
real = 0.0;
string = data+12;
padding = 0;
}
這是一個頭文件。
它要求我出去
使用未聲明的標識符 '的malloc' 的
,也爲strlen的,memcpy和自由。
發生了什麼事?對不起,如果這很簡單,我是C和C++新手
你是否包含stdlib.h? –
@WillAyd我只是將它包括在內,現在錯誤簡化爲strlen和memcpy。謝謝,但這兩個呢? –