implicit declaration using -std=c99

后端 未结 4 636
后悔当初
后悔当初 2020-12-06 05:03

I\'m getting this warning: (-std=c99 -pedantic)

warning: implicit declaration of function ‘strndup’ [-Wimplicit-function-declaration]

4条回答
  •  生来不讨喜
    2020-12-06 05:46

    My man strndup says

    Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
    
           strdup():
               _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
               _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
               || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
           strndup():
               Since glibc 2.10:
                   POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700
               Before glibc 2.10:
                   _GNU_SOURCE
           strdupa(), strndupa(): _GNU_SOURCE

    So I'd need to, eg, #define POSIX_C_SOURCE 200809L before the first #include.
    see man 7 feature_test_macros

提交回复
热议问题