【问题标题】:Error message: undefined symbol _msize in C错误消息:C 中未定义的符号 _msize
【发布时间】:2017-11-24 08:26:18
【问题描述】:

我正在编写动态内存分配程序。在这个程序中,我收到未定义符号_msize 的错误。我也包括 .请帮我解决这个问题。

/* Example of _msize */

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

void main()
{
 long *buffer;
 size_t size;

 buffer = (long *)malloc(100 * sizeof(long));
 size = _msize(buffer);
 printf("The size of the buffer is %d\n", size);
}

【问题讨论】:

  • 这是微软的非便携式产品。你在使用 MSVC 编译器吗?
  • _msize() 不是 C 的标准函数。它看起来像家常便饭。您需要包含正确的头文件才能使用它。查找 _msize() 它所在的头文件。旁注:不要使用不属于 C 标准的 void main()。
  • @LethalProgrammer..在 头文件中,这个函数已经存在。我也包括了那个。 digitalmars.com/rtl/stdlib.html#_msize
  • 您使用的头文件是用于您用于构建的环境吗? IE。匹配编译器,所有需要的库都隐式或显式链接。
  • MSVC 在malloc.h 中有_msize,您已将其包括在内。

标签: c compiler-errors turbo-c++


【解决方案1】:

_msize 不是标准 C。

它来自Microsoft Visual C++(MSVC),您需要像之前那样包含&lt;malloc.h&gt;,并使用 Microsoft 编译器(例如在 Visual Studio 中)。


PS:与你的问题无关:What should main() return in C and C++?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 2011-08-24
    • 2018-10-23
    相关资源
    最近更新 更多