Unverified Commit 8b9be4bd by Tobin C. Harding Committed by Christian Brauner

CODING_STLYE: Simplify explanation for use of 'extern'

Current explanation of rules around usage of 'extern' are overly verbose. It is not necessary to state that functions should be declared in header files, the compiler already enforces this. These rules are simple, they are better described with simple statements. An example is not necessary for such simple rules and serves only to make the document longer. Use two simple statements describing the rules that govern function declaration and the usage of the 'extern' keyword. Signed-off-by: 's avatarTobin C. Harding <me@tobin.cc>
parent 5d48ee40
...@@ -127,26 +127,8 @@ https://www.kernel.org/doc/html/latest/process/coding-style.html ...@@ -127,26 +127,8 @@ https://www.kernel.org/doc/html/latest/process/coding-style.html
#### All Exported Functions Must Be Declared `extern` In A Header File #### All Exported Functions Must Be Declared `extern` In A Header File
- Functions which are used in different files in the library should be declared - Functions declared in header files (`*.h`) should use the `extern` keyword.
in a suitable `*.c` file and exposed in a suitable `*.h` file. When defining - Functions declared in source files (`*.c`) should not use the `extern` keyword.
the function in the `*.c` file the function signature should not be preceded
by the `extern` keyword. When declaring the function signature in the `*.h`
file it must be preceded by the `extern` keyword. For example:
```C
/* Valid function definition in a *.c file */
ssize_t lxc_write_nointr(int fd, const void* buf, size_t count)
{
ssize_t ret;
again:
ret = write(fd, buf, count);
if (ret < 0 && errno == EINTR)
goto again;
return ret;
}
/* Valid function declaration in a *.h file */
extern ssize_t lxc_write_nointr(int fd, const void* buf, size_t count);
```
#### All Names Must Be In lower_case #### All Names Must Be In lower_case
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment