microchip dspic33 malloc函数使用

来源:互联网 发布:layer子域名挖掘机 编辑:程序博客网 时间:2024/06/06 04:50

1. 用法

#include <stdlib.h>     //for maloc, free etc
#include <string.h>     //for memset

void malloc_free_test(void)
{
    long *i;
   
    if ((i = (long *)malloc(50 * sizeof(long))) == NULL)
        printf("Cannot allocate memory\n");
    else {
        printf("Memory allocated[i=%ld]\n", i);
        free(i);
        printf("Memory freed\n");
    }
}


2. 编译报错

elf-ld.exe Error: A heap is required, but has not been specified


3. 解决办法

需要定义heap