Blieque Blieque - 10 months ago 54
C Question

Preventing "warning: implicit declaration of function 'setlinebuf'..."

Both Clang/LLVM and GCC show this warning. I am aware that headers must be included in order to use many functions, but

is included at the top of the file. I've used other functions (e.g.,
) from the same header, and these work fine. Removing the header include causes errors and warnings to be thrown for these other functions, as expected.

I used
clang -MD -MF
to show included header files and checked
, which contains a prototype for
. I found one reference online to
, but this doesn't appear to exist on my system.

I'm using Lubuntu 16.10 x86_64, Clang 3.8.1.

View source: Include on line 1, function use on line 32.

Answer Source

Include this before including stdio.h:

#define _BSD_SOURCE

setlinebuf() is not a standard C function and thus it may not be included by default in stdio.h.

But note that _BSD_SOURCE has been deprecated since glibc 2.20 and been superseded by _DEFAULT_SOURCE.