Conflicting types for “free”

守給你的承諾、 提交于 2019-12-04 10:56:57

You need to add #include <stdlib.h> to provide the prototype for free().

Also, the recommended signature for main() is int main (void).

Basile Starynkevitch

You could implement your malloc and free above some operating system memory address space primitives (modifying the virtual memory of your process), like (on Linux) mmap(2) and munmap. Details are operating system specific.

BTW, if your goal is to write a program using only <stdio.h> most implementations of it are internally using malloc, since the buffer inside every FILE is generally some dynamically allocated byte zone (so concretely, it is generally allocated thru malloc). In other words, the implementation of fopen very probably uses malloc; see also this. Hence if you accept to include <stdio.h> you should accept to include <stdlib.h>...

Notice that several standard C libraries (a.k.a. libc) are free software; you could study -and improve- the source code of GNU glibc or of musl-libc.

See also this answer to a related question.

if your linker command file contains a specific definition of the heap, including a label at the start address and a length label,

then you could write your own version of malloc, free, realloc, calloc, etc.

BTW: the code is calling 'free()' How was that memory allocation made that 'free()' will be returning to the heap?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!