tags:

views:

827

answers:

2

Hi,

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.

+10  A: 

You need:

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

in your code.

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

Alok
and unistd.h for close(2)
Variable Length Coder
Yeah, initially I had just seen the title and the first part of the warnings. Updated.
Alok
+1 for telling the questioner where to find the information. @OP: Don't guess, look it up!
Stephen Canon
+2  A: 

A good way to findout what header file you are missing:

 man <section> <function call>

To find out the section use:

apropos <function call>

Example:

 man 3 memset
 man 2 send

Edit in response to James Morris:

  • Section | Description
  • 1 General commands
  • 2 System calls
  • 3 C library functions
  • 4 Special files (usually devices, those found in /dev) and drivers
  • 5 File formats and conventions
  • 6 Games and screensavers
  • 7 Miscellanea
  • 8 System administration commands and daemons

Source: Wikipedia Man Page

Wergan
Maybe explain why section 3 and section 2?
James Morris