Bob Bob - 2 months ago 21
C Question

dprintf implicit declaration warning

When using dprintf() I'm getting the warning "implicit declaration of dprintf". That tends to mean a necessary file isn't included, but I already included stdio.h, which is supposed to be all that it needs. Is there something else dprintf needs?

Answer

The "feature_test_macros" section of the man page explains that to make stdio.h declare dprintf(), you must first #define _POSIX_C_SOURCE 200809L (or higher) before you #include <stdio.h>. The reason for this is that dprintf() was not standardized until POSIX.1-2008, but <stdio.h> needs to continue to work with code written before that, even if that code used its own identifier named "dprintf". (Defining _GNU_SOURCE or _XOPEN_SOURCE would also work on Linux, but _POSIX_C_SOURCE is the best choice for general portability.)

Comments