为什么我会“使用未声明的标识符’malloc’”?
发布时间:2020-12-14 20:04:08 所属栏目:百科 来源:网络整理
导读:我正在尝试使用XCode并尝试编译其他人的 Windows代码. 有这个: 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 (0xfd
我正在尝试使用XCode并尝试编译其他人的
Windows代码.
有这个: 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; } 这是在头文件中. 它叫我出去
而且对于strlen,memcpy和free. 这是怎么回事?对不起,如果这很简单,我是C和C的新手 解决方法
XCode告诉你,你正在使用一个名为malloc的东西,但它不知道malloc是什么.最好的方法是在代码中添加以下内容:
#include <stdlib.h> // pulls in declaration of malloc,free #include <string.h> // pulls in declaration for strlen. 在以#开头的C和C行中是对预处理器的命令.在此示例中,命令#include将提取另一个文件的完整内容.就好像你自己输入了stdlib.h的内容一样.如果右键单击#include行并选择“转到定义”,XCode将打开stdlib.h.如果你搜索stdlib.h,你会发现: void *malloc(size_t); 这告诉编译器malloc是一个可以使用单个size_t参数调用的函数. 您可以使用“man”命令查找要包含在其他函数中的头文件. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- xml – 将Nokogiri文档转换为Ruby哈希
- ORACLE11g 安装中xhost: unable to open display 问题解决纪
- 如何使用xml.etree解析外部实体,如lxml.etree
- swift3.0 IndexPath替换 NSIndexPath
- Multiple strings.xml files cause order and incomplete p
- xml与bean的转换实例
- Oracle学习01【持续更新】
- oracle em 按钮乱码解决办法及em网页变成英文
- react 使用 fetch 向spring mvc后台发起ajax 请求 options
- flex在线查看word文档