简体   繁体   中英

i am unable to use malloc and free using stdio.h library

I have the following issue/question: I'm currently working on visual studio in CI made a program that uses the functions malloc and free, I am sure I used them well, but when I try to compile I get the following errors:

Error C3861 'free': identifier not found
Error (active)  identifier "free" is undefined  
(same errors for malloc)

the only include statement I made was for stdio.h (which I usually add and it works fine for these functions)

I added stdlib and the problem was resolved, but when I serve this chore I may be downgraded for including a library we did not work with so far, can anyone tell me why the functions don't work with just stdio.h ?

<stdlib.h> is the correct header to include when calling malloc and free . In fact, it's correct to say that you must include <stdlib.h> (directly or indirectly) when calling malloc and free .

There are lots of reasons why it might have worked for you once before even though you didn't. Without seeing that older code, I couldn't say why. Don't worry about it. Just always include <stdlib.h> when calling malloc and free .

Malloc and free is defined under stdlib.h. So without including it your program wont work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM