Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve compiler warning 'implicit declaration of function memset'

Tags:

c++

c

My c code uses 'memset' and 'close'. And I have added:

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

But I still get these warnings:

main.c:259: warning: implicit declaration of function ‘memset’ main.c:259: warning: incompatible implicit declaration of built-in function ‘memset’ main.c:268: warning: implicit declaration of function ‘close’ main.c:259: warning: incompatible implicit declaration of built-in function ‘close’ 

Can you please tell me how can I resolve these warnings?

Thank you.

like image 689
hap497 Avatar asked Jan 27 '10 04:01

hap497


People also ask

How do you fix an implicit function declaration?

Function name typo: Often the function name of the declaration does not exactly match the function name that is being called. For example, startBenchmark() is declared while StartBenchmark() is being called. I recommend to fix this by copy-&-pasting the function name from the declaration to wherever you call it.

What is implicit declaration of function warning?

Implicit declaration of functions is not allowed; every function must be explicitly declared before it can be called. In C90, if a function is called without an explicit prototype, the compiler provides an implicit declaration.

What is incompatible implicit declaration of built in function?

If an implicit declaration does not match the built-in definition, you get this warning. To fix the problem, you have to declare the functions before using them; normally you do this by including the appropriate header.


1 Answers

You need:

#include <string.h> /* memset */ #include <unistd.h> /* close */ 

in your code.

References: POSIX for close, the C standard for memset.

like image 119
Alok Singhal Avatar answered Oct 11 '22 08:10

Alok Singhal