了解如何解決C語言中的隱式聲明庫函數警告
編譯時C程序,您可能會發現編譯器向您發出類似於以下內容的警告
hello.c:6:3: warning: implicitly declaring library function
'printf' with type 'int (const char *, ...)'
[-Wimplicit-function-declaration]
printf("Name length: %u", length);
^or
hello.c:5:16: warning: implicitly declaring library function
'strlen' with type 'unsigned long (const char *)'
[-Wimplicit-function-declaration]
int length = strlen(name);
^This problem occurs because you used a function from the standard library without first including the appropriate header file.
The compiler will also give you a suggestion, like the following one:
hello.c:5:16: note: include the header <string.h> or
explicitly provide a declaration for 'strlen'which points you in the right direction.
In this case, adding
#include <stdio.h>
at the top of the C file will solve the issue.
Download my free C Handbook
More clang tutorials:
- Introduction to the C Programming Language
- C Variables and types
- C Constants
- C Operators
- C Conditionals
- How to work with loops in C
- Introduction to C Arrays
- How to determine the length of an array in C
- Introduction to C Strings
- How to find the length of a string in C
- Introduction to C Pointers
- Looping through an array with C
- Booleans in C
- Introduction to C Functions
- How to use NULL in C
- Basic I/O concepts in C
- Double quotes vs single quotes in C
- How to return a string from a C function
- How to solve the implicitly declaring library function warning in C
- How to check a character value in C
- How to print the percentage character using `printf()` in C
- C conversion specifiers and modifiers
- How to access the command line parameters in C
- Scope of variables in C
- Can you nest functions in C?
- Static variables in C
- C Global Variables
- The typedef keyword in C
- C Enumerated Types
- C Structures
- C Header Files
- The C Preprocessor