iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么我会“使用未声明的标识符’malloc’”?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我正在尝试使用XCode并尝试编译其他人的 Windows代码. 有这个: inline GMVariable(const char* a) { unsigned int len = strlen(a); char *data = (char*)(malloc(len+13)); if(data==NULL) { } // Apparently the fi
我正在尝试使用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参数调用函数.

您可以使用“R_956_11845@an”命令查找要包含在其他函数中的头文件.

大佬总结

以上是大佬教程为你收集整理的为什么我会“使用未声明的标识符’malloc’”?全部内容,希望文章能够帮你解决为什么我会“使用未声明的标识符’malloc’”?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。