Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22264

gcc warning "implicit declaration of function ‘strnlen’" when dialect c99 or c11 used

$
0
0

EDIT Question is: how do I remove the warning /EDITcompiling (special cut-down test with just one #include)

#include <string.h>void DeleteMe(){    const char* pC = "ABC";    int nLen = strnlen(pC, 255);    char buffer[256];    strncpy(buffer, pC, nLen);}

With no dialect, it compiles no warning as

Building file: ../EzyThread.cInvoking: GCC C Compilergcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"EzyThread.d" -MT"EzyThread.o" -o "EzyThread.o""../EzyThread.c"Finished building: ../EzyThread.c

making dialect c99 gives warning

Building file: ../EzyThread.cInvoking: GCC C Compilergcc -std=c99 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"EzyThread.d" -MT"EzyThread.o" -o "EzyThread.o""../EzyThread.c"../EzyThread.c: In function ‘DeleteMe’:../EzyThread.c:4:13: warning: implicit declaration of function ‘strnlen’ [-Wimplicit-function-declaration]  int nLen = strnlen(pC, 255);             ^Finished building: ../EzyThread.c

making dialect c11 (my preferred option) gives warning

Building file: ../EzyThread.cInvoking: GCC C Compilergcc -std=c11 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"EzyThread.d" -MT"EzyThread.o" -o "EzyThread.o""../EzyThread.c"../EzyThread.c: In function ‘DeleteMe’:../EzyThread.c:4:13: warning: implicit declaration of function ‘strnlen’ [-Wimplicit-function-declaration]  int nLen = strnlen(pC, 255);             ^Finished building: ../EzyThread.c

Extra info:

  • Oher parts of the project fail to compile under c90, so no info available

  • Running under Ubuntu 16.04 which was an upgrade of 14.04

  • Using

    Eclipse IDE for C/C++ Developers

    Version: Neon.3 Release (4.6.3)Build id: 20170314-1500

  • man strnlen

gives

STRNLEN(3)                 Linux Programmer's Manual                STRNLEN(3)NAME       strnlen - determine the length of a fixed-size stringSYNOPSIS       #include <string.h>       size_t strnlen(const char *s, size_t maxlen);   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):       strnlen():           Since glibc 2.10:               _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L           Before glibc 2.10:               _GNU_SOURCE

Viewing all articles
Browse latest Browse all 22264


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>