History

Update developers documentation with coding conventions.

Victor Vasiliev committed 14 years ago

Commit 9b9815e1 parent 51a16071 file · +97 −26Browse files

Unified · Split

doc/developer.texi+97−26
@@ -45,48 +45,61 @@ mailing list. · 44 unmodified lines
45@anchor{Coding Rules}45@anchor{Coding Rules}
46@section Coding Rules46@section Coding Rules
47 47
48Libav is programmed in the ISO C90 language with a few additional48@subsection Code formatting conventions
49features from ISO C99, namely:49The code is written in K&R C style. That means the following:
50@itemize @bullet50@itemize @bullet
51@item51@item
52the @samp{inline} keyword;52The control statements are formatted by putting space betwen the statement and parenthesis
53in the following way:
54@example
55for (i = 0; i < filter->input_count; i ++) @{
56@end example
53@item57@item
54@samp{//} comments;58The case statement is always located at the same level as the switch itself:
59@example
60switch (link->init_state) @{
61case AVLINK_INIT:
62 continue;
63case AVLINK_STARTINIT:
64 av_log(filter, AV_LOG_INFO, "circular filter chain detected");
65 return 0;
66@end example
55@item67@item
56designated struct initializers (@samp{struct s x = @{ .i = 17 @};})68Braces in function declarations are written on the new line:
69@example
70const char *avfilter_configuration(void)
71@{
72 return LIBAV_CONFIGURATION;
73@}
74@end example
57@item75@item
58compound literals (@samp{x = (struct s) @{ 17, 23 @};})76In case of a single-statement if, no curly braces are required:
77@example
78if (!pic || !picref)
79 goto fail;
80@end example
81@item
82Do not put spaces immediately inside parenthesis. @samp{if (ret)} is a valid style; @samp{if ( ret )} is not.
59@end itemize83@end itemize
60 84
61These features are supported by all compilers we care about, so we will not85There are the following guidelines regarding the indentation in files:
62accept patches to remove their use unless they absolutely do not impair
63clarity and performance.
64
65All code must compile with recent versions of GCC and a number of other
66currently supported compilers. To ensure compatibility, please do not use
67additional C99 features or GCC extensions. Especially watch out for:
68@itemize @bullet86@itemize @bullet
69@item87@item
70mixing statements and declarations;
71@item
72@samp{long long} (use @samp{int64_t} instead);
73@item
74@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar;
75@item
76GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}).
77@end itemize
78
79Indent size is 4.88Indent size is 4.
80The presentation is one inspired by 'indent -i4 -kr -nut'.89@item
81The TAB character is forbidden outside of Makefiles as is any90The TAB character is forbidden outside of Makefiles as is any
82form of trailing whitespace. Commits containing either will be91form of trailing whitespace. Commits containing either will be
83rejected by the git repository.92rejected by the git repository.
93@item
94You should try to limit your code lines to 80 characters; however, do so if and only if this improves readability.
95@end itemize
96The presentation is one inspired by 'indent -i4 -kr -nut'.
84 97
85The main priority in Libav is simplicity and small code size in order to98The main priority in Libav is simplicity and small code size in order to
86minimize the bug count.99minimize the bug count.
87 100
88Comments: Use the JavaDoc/Doxygen101@subsection Comments
89format (see examples below) so that code documentation102Use the JavaDoc/Doxygen format (see examples below) so that code documentation
90can be generated automatically. All nontrivial functions should have a comment103can be generated automatically. All nontrivial functions should have a comment
91above them explaining what the function does, even if it is just one sentence.104above them explaining what the function does, even if it is just one sentence.
92All structures and their member variables should be documented, too.105All structures and their member variables should be documented, too.
@@ -120,11 +133,69 @@ int myfunc(int my_parameter) · 27 unmodified lines
120...133...
121@end example134@end example
122 135
136@subsection C language features
137
138Libav is programmed in the ISO C90 language with a few additional
139features from ISO C99, namely:
140@itemize @bullet
141@item
142the @samp{inline} keyword;
143@item
144@samp{//} comments;
145@item
146designated struct initializers (@samp{struct s x = @{ .i = 17 @};})
147@item
148compound literals (@samp{x = (struct s) @{ 17, 23 @};})
149@end itemize
150
151These features are supported by all compilers we care about, so we will not
152accept patches to remove their use unless they absolutely do not impair
153clarity and performance.
154
155All code must compile with recent versions of GCC and a number of other
156currently supported compilers. To ensure compatibility, please do not use
157additional C99 features or GCC extensions. Especially watch out for:
158@itemize @bullet
159@item
160mixing statements and declarations;
161@item
162@samp{long long} (use @samp{int64_t} instead);
163@item
164@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar;
165@item
166GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}).
167@end itemize
168
169@subsection Naming conventions
170All names are using underscores (_), not CamelCase. For example, @samp{avfilter_get_video_buffer} is
171a valid function name and @samp{AVFilterGetVideo} is not. The only exception from this are structure names;
172they should always be in the CamelCase
173
174There are following conventions for naming variables and functions:
175@itemize @bullet
176@item
177For local variables no prefix is required.
178@item
179For variables and functions declared as @code{static} no prefixes are required.
180@item
181For variables and functions used internally by the library, @code{ff_} prefix should be used.
182For example, @samp{ff_w64_demuxer}.
183@item
184For variables and functions used internally across multiple libraries, use @code{avpriv_}. For example,
185@samp{avpriv_aac_parse_header}.
186@item
187For exported names, each library has its own prefixes. Just check the existing code and name accordingly.
188@end itemize
189
190@subsection Miscellanous conventions
191@itemize @bullet
192@item
123fprintf and printf are forbidden in libavformat and libavcodec,193fprintf and printf are forbidden in libavformat and libavcodec,
124please use av_log() instead.194please use av_log() instead.
125 195@item
126Casts should be used only when necessary. Unneeded parentheses196Casts should be used only when necessary. Unneeded parentheses
127should also be avoided if they don't make the code easier to understand.197should also be avoided if they don't make the code easier to understand.
198@end itemize
128 199
129@section Development Policy200@section Development Policy
130 201

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t