VirtualBox

source: vbox/trunk/doc/VBox-CodingGuidelines.cpp@ 67954

Last change on this file since 67954 was 63292, checked in by vboxsync, 8 years ago

VBox-CodingGuidelines: Avoid where ever possible the use of the types 'long' and 'unsigned long' as these differs in size between windows and the other hosts!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.7 KB
Line 
1/* $Id: VBox-CodingGuidelines.cpp 63292 2016-08-10 15:49:33Z vboxsync $ */
2/** @file
3 * VBox - Coding Guidelines.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/** @page pg_vbox_guideline VBox Coding Guidelines
19 *
20 * The VBox Coding guidelines are followed by all of VBox with the exception of
21 * qemu. Qemu is using whatever the frenchman does.
22 *
23 * There are a few compulsory rules and a bunch of optional ones. The following
24 * sections will describe these in details. In addition there is a section of
25 * Subversion 'rules'.
26 *
27 *
28 *
29 * @section sec_vbox_guideline_compulsory Compulsory
30 *
31 *
32 * - The indentation size is 4 chars.
33 *
34 * - Tabs are only ever used in makefiles.
35 *
36 * - Use RT and VBOX types.
37 *
38 * - Use Runtime functions.
39 *
40 * - Use the standard bool, uintptr_t, intptr_t and [u]int[1-9+]_t types.
41 *
42 * - Avoid using plain unsigned and int.
43 *
44 * - Use static wherever possible. This makes the namespace less polluted
45 * and avoids nasty name clash problems which can occur, especially on
46 * Unix-like systems. (1) It also simplifies locating callers when
47 * changing it (single source file vs entire VBox tree).
48 *
49 * - Public names are of the form Domain[Subdomain[]]Method, using mixed
50 * casing to mark the words. The main domain is all uppercase.
51 * (Think like java, mapping domain and subdomain to packages/classes.)
52 *
53 * - Public names are always declared using the appropriate DECL macro. (2)
54 *
55 * - Internal names starts with a lowercased main domain.
56 *
57 * - Defines are all uppercase and separate words with underscore.
58 * This applies to enum values too.
59 *
60 * - Typedefs are all uppercase and contain no underscores to distinguish
61 * them from defines.
62 *
63 * - Pointer typedefs start with 'P'. If pointer to const then 'PC'.
64 *
65 * - Function typedefs start with 'FN'. If pointer to FN then 'PFN'.
66 *
67 * - All files are case sensitive.
68 *
69 * - Slashes are unix slashes ('/') runtime converts when necessary.
70 *
71 * - char strings are UTF-8.
72 *
73 * - Strings from any external source must be treated with utmost care as
74 * they do not have to be valid UTF-8. Only trust internal strings.
75 *
76 * - All functions return VBox status codes. There are three general
77 * exceptions from this:
78 * -# Predicate functions. These are function which are boolean in
79 * nature and usage. They return bool. The function name will
80 * include 'Has', 'Is' or similar.
81 * -# Functions which by nature cannot possibly fail.
82 * These return void.
83 * -# "Get"-functions which return what they ask for.
84 * A get function becomes a "Query" function if there is any
85 * doubt about getting what is ask for.
86 *
87 * - VBox status codes have three subdivisions:
88 * -# Errors, which are VERR_ prefixed and negative.
89 * -# Warnings, which are VWRN_ prefixed and positive.
90 * -# Informational, which are VINF_ prefixed and positive.
91 *
92 * - Platform/OS operation are generalized and put in the IPRT.
93 *
94 * - Other useful constructs are also put in the IPRT.
95 *
96 * - The code shall not cause compiler warnings. Check this on ALL
97 * the platforms.
98 *
99 * - The use of symbols leading with single or double underscores is
100 * forbidden as that intrudes on reserved compiler/system namespace. (3)
101 *
102 * - All files have file headers with $Id and a file tag which describes
103 * the file in a sentence or two.
104 * Note: Use the svn-ps.cmd/svn-ps.sh utility with the -a option to add
105 * new sources with keyword expansion and exporting correctly
106 * configured.
107 *
108 * - All public functions are fully documented in Doxygen style using the
109 * javadoc dialect (using the 'at' instead of the 'slash' as
110 * commandprefix.)
111 *
112 * - All structures in header files are described, including all their
113 * members. (Doxygen style, of course.)
114 *
115 * - All modules have a documentation '\@page' in the main source file
116 * which describes the intent and actual implementation.
117 *
118 * - Code which is doing things that are not immediately comprehensible
119 * shall include explanatory comments.
120 *
121 * - Documentation and comments are kept up to date.
122 *
123 * - Headers in /include/VBox shall not contain any slash-slash C++
124 * comments, only ANSI C comments!
125 *
126 * - Comments on \#else indicates what begins while the comment on a
127 * \#endif indicates what ended. Only add these when there are more than
128 * a few lines (6-10) of \#ifdef'ed code, otherwise they're just clutter.
129 *
130 *
131 * (1) It is common practice on Unix to have a single symbol namespace for an
132 * entire process. If one is careless symbols might be resolved in a
133 * different way that one expects, leading to weird problems.
134 *
135 * (2) This is common practice among most projects dealing with modules in
136 * shared libraries. The Windows / PE __declspect(import) and
137 * __declspect(export) constructs are the main reason for this.
138 * OTOH, we do perhaps have a bit too detailed graining of this in VMM...
139 *
140 * (3) There are guys out there grepping public sources for symbols leading with
141 * single and double underscores as well as gotos and other things
142 * considered bad practice. They'll post statistics on how bad our sources
143 * are on some mailing list, forum or similar.
144 *
145 *
146 * @subsection sec_vbox_guideline_compulsory_sub64 64-bit and 32-bit
147 *
148 * Here are some amendments which address 64-bit vs. 32-bit portability issues.
149 *
150 * Some facts first:
151 *
152 * - On 64-bit Windows the type long remains 32-bit. On nearly all other
153 * 64-bit platforms long is 64-bit.
154 *
155 * - On all 64-bit platforms we care about, int is 32-bit, short is 16 bit
156 * and char is 8-bit.
157 * (I don't know about any platforms yet where this isn't true.)
158 *
159 * - size_t, ssize_t, uintptr_t, ptrdiff_t and similar are all 64-bit on
160 * 64-bit platforms. (These are 32-bit on 32-bit platforms.)
161 *
162 * - There is no inline assembly support in the 64-bit Microsoft compilers.
163 *
164 *
165 * Now for the guidelines:
166 *
167 * - Never, ever, use int, long, ULONG, LONG, DWORD or similar to cast a
168 * pointer to integer. Use uintptr_t or intptr_t. If you have to use
169 * NT/Windows types, there is the choice of ULONG_PTR and DWORD_PTR.
170 *
171 * - Avoid where ever possible the use of the types 'long' and 'unsigned
172 * long' as these differs in size between windows and the other hosts
173 * (see above).
174 *
175 * - RT_OS_WINDOWS is defined to indicate Windows. Do not use __WIN32__,
176 * __WIN64__ and __WIN__ because they are all deprecated and scheduled
177 * for removal (if not removed already). Do not use the compiler
178 * defined _WIN32, _WIN64, or similar either. The bitness can be
179 * determined by testing ARCH_BITS.
180 * Example:
181 * @code
182 * #ifdef RT_OS_WINDOWS
183 * // call win32/64 api.
184 * #endif
185 * #ifdef RT_OS_WINDOWS
186 * # if ARCH_BITS == 64
187 * // call win64 api.
188 * # else // ARCH_BITS == 32
189 * // call win32 api.
190 * # endif // ARCH_BITS == 32
191 * #else // !RT_OS_WINDOWS
192 * // call posix api
193 * #endif // !RT_OS_WINDOWS
194 * @endcode
195 *
196 * - There are RT_OS_xxx defines for each OS, just like RT_OS_WINDOWS
197 * mentioned above. Use these defines instead of any predefined
198 * compiler stuff or defines from system headers.
199 *
200 * - RT_ARCH_X86 is defined when compiling for the x86 the architecture.
201 * Do not use __x86__, __X86__, __[Ii]386__, __[Ii]586__, or similar
202 * for this purpose.
203 *
204 * - RT_ARCH_AMD64 is defined when compiling for the AMD64 architecture.
205 * Do not use __AMD64__, __amd64__ or __x64_86__.
206 *
207 * - Take care and use size_t when you have to, esp. when passing a pointer
208 * to a size_t as a parameter.
209 *
210 * - Be wary of type promotion to (signed) integer. For example the
211 * following will cause u8 to be promoted to int in the shift, and then
212 * sign extended in the assignment 64-bit:
213 * @code
214 * uint8_t u8 = 0xfe;
215 * uint64_t u64 = u8 << 24;
216 * // u64 == 0xfffffffffe000000
217 * @endcode
218 *
219 *
220 * @subsection sec_vbox_guideline_compulsory_cppmain C++ guidelines for Main
221 *
222 * Main is currently (2009) full of hard-to-maintain code that uses complicated
223 * templates. The new mid-term goal for Main is to have less custom templates
224 * instead of more for the following reasons:
225 *
226 * - Template code is harder to read and understand. Custom templates create
227 * territories which only the code writer understands.
228 *
229 * - Errors in using templates create terrible C++ compiler messages.
230 *
231 * - Template code is really hard to look at in a debugger.
232 *
233 * - Templates slow down the compiler a lot.
234 *
235 * In particular, the following bits should be considered deprecated and should
236 * NOT be used in new code:
237 *
238 * - everything in include/iprt/cpputils.h (auto_ref_ptr, exception_trap_base,
239 * char_auto_ptr and friends)
240 *
241 * Generally, in many cases, a simple class with a proper destructor can achieve
242 * the same effect as a 1,000-line template include file, and the code is
243 * much more accessible that way.
244 *
245 * Using standard STL templates like std::list, std::vector and std::map is OK.
246 * Exceptions are:
247 *
248 * - Guest Additions because we don't want to link against libstdc++ there.
249 *
250 * - std::string should not be used because we have iprt::MiniString and
251 * com::Utf8Str which can convert efficiently with COM's UTF-16 strings.
252 *
253 * - std::auto_ptr<> in general; that part of the C++ standard is just broken.
254 * Write a destructor that calls delete.
255 *
256 *
257 * @subsection sec_vbox_guideline_compulsory_cppqtgui C++ guidelines for the Qt GUI
258 *
259 * The Qt GUI is currently (2010) on its way to become more compatible to the
260 * rest of VirtualBox coding style wise. From now on, all the coding style
261 * rules described in this file are also mandatory for the Qt GUI. Additionally
262 * the following rules should be respected:
263 *
264 * - GUI classes which correspond to GUI tasks should be prefixed by UI (no VBox anymore)
265 *
266 * - Classes which extents some of the Qt classes should be prefix by QI
267 *
268 * - General task classes should be prefixed by C
269 *
270 * - Slots are prefixed by slt -> sltName
271 *
272 * - Signals are prefixed by sig -> sigName
273 *
274 * - Use Qt classes for lists, strings and so on, the use of STL classes should
275 * be avoided
276 *
277 * - All files like .cpp, .h, .ui, which belong together are located in the
278 * same directory and named the same
279 *
280 *
281 * @subsection sec_vbox_guideline_compulsory_xslt XSLT
282 *
283 * XSLT (eXtensible Stylesheet Language Transformations) is used quite a bit in
284 * the Main API area of VirtualBox to generate sources and bindings to that API.
285 * There are a couple of common pitfalls worth mentioning:
286 *
287 * - Never do repeated //interface[@name=...] and //enum[@name=...] lookups
288 * because they are expensive. Instead delcare xsl:key elements for these
289 * searches and do the lookup using the key() function. xsltproc uses
290 * (per current document) hash tables for each xsl:key, i.e. very fast.
291 *
292 * - When output type is 'text' make sure to call xsltprocNewlineOutputHack
293 * from typemap-shared.inc.xsl every few KB of output, or xsltproc will
294 * end up wasting all the time reallocating the output buffer.
295 *
296 *
297 * @subsection sec_vbox_guideline_compulsory_doxygen Doxygen Comments
298 *
299 * As mentioned above, we shall use doxygen/javadoc style commenting of public
300 * functions, typedefs, classes and such. It is preferred to use this style in
301 * as many places as possible.
302 *
303 * A couple of hints on how to best write doxygen comments:
304 *
305 * - A good class, method, function, structure or enum doxygen comment
306 * starts with a one line sentence giving a brief description of the
307 * item. Details comes in a new paragraph (after blank line).
308 *
309 * - Except for list generators like \@todo, \@cfgm, \@gcfgm and others,
310 * all doxygen comments are related to things in the code. So, for
311 * instance you DO NOT add a doxygen \@note comment in the middle of a
312 * because you've got something important to note, you add a normal
313 * comment like 'Note! blah, very importan blah!'
314 *
315 * - We do NOT use TODO/XXX/BUGBUG or similar markers in the code to flag
316 * things needing fixing later, we always use \@todo doxygen comments.
317 *
318 * - There is no colon after the \@todo. And it is ALWAYS in a doxygen
319 * comment.
320 *
321 * - The \@retval tag is used to explain status codes a method/function may
322 * returns. It is not used to describe output parameters, that is done
323 * using the \@param or \@param[out] tag.
324 *
325 * See https://www.stack.nl/~dimitri/doxygen/manual/index.html for the official
326 * doxygen documention.
327 *
328 *
329 * @section sec_vbox_guideline_optional Optional
330 *
331 * First part is the actual coding style and all the prefixes. The second part
332 * is a bunch of good advice.
333 *
334 *
335 * @subsection sec_vbox_guideline_optional_layout The code layout
336 *
337 * - Max line length is 130 chars. Exceptions are table-like
338 * code/initializers and Log*() statements (don't waste unnecessary
339 * vertical space on debug logging).
340 *
341 * - Comments should try stay within the usual 80 columns as these are
342 * denser and too long lines may be harder to read.
343 *
344 * - Curly brackets are not indented. Example:
345 * @code
346 * if (true)
347 * {
348 * Something1();
349 * Something2();
350 * }
351 * else
352 * {
353 * SomethingElse1().
354 * SomethingElse2().
355 * }
356 * @endcode
357 *
358 * - Space before the parentheses when it comes after a C keyword.
359 *
360 * - No space between argument and parentheses. Exception for complex
361 * expression. Example:
362 * @code
363 * if (PATMR3IsPatchGCAddr(pVM, GCPtr))
364 * @endcode
365 *
366 * - The else of an if is always the first statement on a line. (No curly
367 * stuff before it!)
368 *
369 * - else and if go on the same line if no { compound statement }
370 * follows the if. Example:
371 * @code
372 * if (fFlags & MYFLAGS_1)
373 * fFlags &= ~MYFLAGS_10;
374 * else if (fFlags & MYFLAGS_2)
375 * {
376 * fFlags &= ~MYFLAGS_MASK;
377 * fFlags |= MYFLAGS_5;
378 * }
379 * else if (fFlags & MYFLAGS_3)
380 * @endcode
381 *
382 *
383 * - Slightly complex boolean expressions are split into multiple lines,
384 * putting the operators first on the line and indenting it all according
385 * to the nesting of the expression. The purpose is to make it as easy as
386 * possible to read. Example:
387 * @code
388 * if ( RT_SUCCESS(rc)
389 * || (fFlags & SOME_FLAG))
390 * @endcode
391 *
392 * - When 'if' or 'while' statements gets long, the closing parentheses
393 * goes right below the opening parentheses. This may be applied to
394 * sub-expression. Example:
395 * @code
396 * if ( RT_SUCCESS(rc)
397 * || ( fSomeStuff
398 * && fSomeOtherStuff
399 * && fEvenMoreStuff
400 * )
401 * || SomePredicateFunction()
402 * )
403 * {
404 * ...
405 * }
406 * @endcode
407 *
408 * - The case is indented from the switch (to avoid having the braces for
409 * the 'case' at the same level as the 'switch' statement).
410 *
411 * - If a case needs curly brackets they contain the entire case, are not
412 * indented from the case, and the break or return is placed inside them.
413 * Example:
414 * @code
415 * switch (pCur->eType)
416 * {
417 * case PGMMAPPINGTYPE_PAGETABLES:
418 * {
419 * unsigned iPDE = pCur->GCPtr >> PGDIR_SHIFT;
420 * unsigned iPT = (pCur->GCPtrEnd - pCur->GCPtr) >> PGDIR_SHIFT;
421 * while (iPT-- > 0)
422 * if (pPD->a[iPDE + iPT].n.u1Present)
423 * return VERR_HYPERVISOR_CONFLICT;
424 * break;
425 * }
426 * }
427 * @endcode
428 *
429 * - In a do while construction, the while is on the same line as the
430 * closing "}" if any are used.
431 * Example:
432 * @code
433 * do
434 * {
435 * stuff;
436 * i--;
437 * } while (i > 0);
438 * @endcode
439 *
440 * - Comments are in C style. C++ style comments are used for temporary
441 * disabling a few lines of code.
442 *
443 * - No unnecessary parentheses in expressions (just don't over do this
444 * so that gcc / msc starts bitching). Find a correct C/C++ operator
445 * precedence table if needed.
446 *
447 * - 'for (;;)' is preferred over 'while (true)' and 'while (1)'.
448 *
449 * - Parameters are indented to the start parentheses when breaking up
450 * function calls, declarations or prototypes. (This is in line with
451 * how 'if', 'for' and 'while' statements are done as well.) Example:
452 * @code
453 * RTPROCESS hProcess;
454 * int rc = RTProcCreateEx(papszArgs[0],
455 * papszArgs,
456 * RTENV_DEFAULT,
457 * fFlags,
458 * NULL, // phStdIn
459 * NULL, // phStdOut
460 * NULL, // phStdErr
461 * NULL, // pszAsUser
462 * NULL, // pszPassword
463 * &hProcess);
464 * @endcode
465 *
466 * - That Dijkstra is dead is no excuse for using gotos.
467 *
468 * - Using do-while-false loops to avoid gotos is considered very bad form.
469 * They create hard to read code. They tend to be either too short (i.e.
470 * pointless) or way to long (split up the function already), making
471 * tracking the state is difficult and prone to bugs. Also, they cause
472 * the compiler to generate suboptimal code, because the break branches
473 * are by preferred over the main code flow (MSC has no branch hinting!).
474 * Instead, do make use the 130 columns (i.e. nested ifs) and split
475 * the code up into more functions!
476 *
477 *
478 * @subsection sec_vbox_guideline_optional_prefix Variable / Member Prefixes
479 *
480 * Prefixes are meant to provide extra context clues to a variable/member, we
481 * therefore avoid using prefixes that just indicating the type if a better
482 * choice is available.
483 *
484 *
485 * The prefixes:
486 *
487 * - The 'g_' (or 'g') prefix means a global variable, either on file or module level.
488 *
489 * - The 's_' (or 's') prefix means a static variable inside a function or
490 * class. This is not used for static variables on file level, use 'g_'
491 * for those (logical, right).
492 *
493 * - The 'm_' (or 'm') prefix means a class data member.
494 *
495 * In new code in Main, use "m_" (and common sense). As an exception,
496 * in Main, if a class encapsulates its member variables in an anonymous
497 * structure which is declared in the class, but defined only in the
498 * implementation (like this: 'class X { struct Data; Data *m; }'), then
499 * the pointer to that struct is called 'm' itself and its members then
500 * need no prefix, because the members are accessed with 'm->member'
501 * already which is clear enough.
502 *
503 * - The 'a_' prefix means a parameter (argument) variable. This is
504 * sometimes written 'a' in parts of the source code that does not use
505 * the array prefix.
506 *
507 * - The 'p' prefix means pointer. For instance 'pVM' is pointer to VM.
508 *
509 * - The 'r' prefix means that something is passed by reference.
510 *
511 * - The 'k' prefix means that something is a constant. For instance
512 * 'enum { kStuff };'. This is usually not used in combination with
513 * 'p', 'r' or any such thing, it's main main use is to make enums
514 * easily identifiable.
515 *
516 * - The 'a' prefix means array. For instance 'aPages' could be read as
517 * array of pages.
518 *
519 * - The 'c' prefix means count. For instance 'cbBlock' could be read,
520 * count of bytes in block. (1)
521 *
522 * - The 'cx' prefix means width (count of 'x' units).
523 *
524 * - The 'cy' prefix means height (count of 'y' units).
525 *
526 * - The 'x', 'y' and 'z' prefix refers to the x-, y- , and z-axis
527 * respectively.
528 *
529 * - The 'off' prefix means offset.
530 *
531 * - The 'i' or 'idx' prefixes usually means index. Although the 'i' one
532 * can sometimes just mean signed integer.
533 *
534 * - The 'i[1-9]+' prefix means a fixed bit size variable. Frequently
535 * used with the int[1-9]+_t types where the width is really important.
536 * In most cases 'i' is more appropriate. [type]
537 *
538 * - The 'e' (or 'enm') prefix means enum.
539 *
540 * - The 'u' prefix usually means unsigned integer. Exceptions follows.
541 *
542 * - The 'u[1-9]+' prefix means a fixed bit size variable. Frequently
543 * used with the uint[1-9]+_t types and with bitfields where the width is
544 * really important. In most cases 'u' or 'b' (byte) would be more
545 * appropriate. [type]
546 *
547 * - The 'b' prefix means byte or bytes. [type]
548 *
549 * - The 'f' prefix means flags. Flags are unsigned integers of some kind
550 * or booleans.
551 *
552 * - TODO: need prefix for real float. [type]
553 *
554 * - The 'rd' prefix means real double and is used for 'double' variables.
555 * [type]
556 *
557 * - The 'lrd' prefix means long real double and is used for 'long double'
558 * variables. [type]
559 *
560 * - The 'ch' prefix means a char, the (signed) char type. [type]
561 *
562 * - The 'wc' prefix means a wide/windows char, the RTUTF16 type. [type]
563 *
564 * - The 'uc' prefix means a Unicode Code point, the RTUNICP type. [type]
565 *
566 * - The 'uch' prefix means unsigned char. It's rarely used. [type]
567 *
568 * - The 'sz' prefix means zero terminated character string (array of
569 * chars). (UTF-8)
570 *
571 * - The 'wsz' prefix means zero terminated wide/windows character string
572 * (array of RTUTF16).
573 *
574 * - The 'usz' prefix means zero terminated Unicode string (array of
575 * RTUNICP).
576 *
577 * - The 'str' prefix means C++ string; either a std::string or, in Main,
578 * a Utf8Str or, in Qt, a QString. When used with 'p', 'r', 'a' or 'c'
579 * the first letter should be capitalized.
580 *
581 * - The 'bstr' prefix, in Main, means a UTF-16 Bstr. When used with 'p',
582 * 'r', 'a' or 'c' the first letter should be capitalized.
583 *
584 * - The 'pfn' prefix means pointer to function. Common usage is 'pfnCallback'
585 * and such like.
586 *
587 * - The 'psz' prefix is a combination of 'p' and 'sz' and thus means
588 * pointer to a zero terminated character string. (UTF-8)
589 *
590 * - The 'pcsz' prefix is used to indicate constant string pointers in
591 * parts of the code. Most code uses 'psz' for const and non-const
592 * string pointers, so please ignore this one.
593 *
594 * - The 'l' prefix means (signed) long. We try avoid using this,
595 * expecially with the 'LONG' types in Main as these are not 'long' on
596 * 64-bit non-Windows platforms and can cause confusion. Alternatives:
597 * 'i' or 'i32'. [type]
598 *
599 * - The 'ul' prefix means unsigned long. We try avoid using this,
600 * expecially with the 'ULONG' types in Main as these are not 'unsigned
601 * long' on 64-bit non-Windows platforms and can cause confusion.
602 * Alternatives: 'u' or 'u32'. [type]
603 *
604 *
605 * (1) Except in the occasional 'pcsz' prefix, the 'c' prefix is never ever
606 * used in the meaning 'const'.
607 *
608 *
609 * @subsection sec_vbox_guideline_optional_misc Misc / Advice / Stuff
610 *
611 * - When writing code think as the reader.
612 *
613 * - When writing code think as the compiler. (2)
614 *
615 * - When reading code think as if it's full of bugs - find them and fix them.
616 *
617 * - Pointer within range tests like:
618 * @code
619 * if ((uintptr_t)pv >= (uintptr_t)pvBase && (uintptr_t)pv < (uintptr_t)pvBase + cbRange)
620 * @endcode
621 * Can also be written as (assuming cbRange unsigned):
622 * @code
623 * if ((uintptr_t)pv - (uintptr_t)pvBase < cbRange)
624 * @endcode
625 * Which is shorter and potentially faster. (1)
626 *
627 * - Avoid unnecessary casting. All pointers automatically cast down to
628 * void *, at least for non class instance pointers.
629 *
630 * - It's very very bad practise to write a function larger than a
631 * screen full (1024x768) without any comprehensibility and explaining
632 * comments.
633 *
634 * - More to come....
635 *
636 *
637 * (1) Important, be very careful with the casting. In particular, note that
638 * a compiler might treat pointers as signed (IIRC).
639 *
640 * (2) "A really advanced hacker comes to understand the true inner workings of
641 * the machine - he sees through the language he's working in and glimpses
642 * the secret functioning of the binary code - becomes a Ba'al Shem of
643 * sorts." (Neal Stephenson "Snow Crash")
644 *
645 *
646 *
647 * @section sec_vbox_guideline_warnings Compiler Warnings
648 *
649 * The code should when possible compile on all platforms and compilers without any
650 * warnings. That's a nice idea, however, if it means making the code harder to read,
651 * less portable, unreliable or similar, the warning should not be fixed.
652 *
653 * Some of the warnings can seem kind of innocent at first glance. So, let's take the
654 * most common ones and explain them.
655 *
656 *
657 * @subsection sec_vbox_guideline_warnings_signed_unsigned_compare Signed / Unsigned Compare
658 *
659 * GCC says: "warning: comparison between signed and unsigned integer expressions"
660 * MSC says: "warning C4018: '<|<=|==|>=|>' : signed/unsigned mismatch"
661 *
662 * The following example will not output what you expect:
663@code
664#include <stdio.h>
665int main()
666{
667 signed long a = -1;
668 unsigned long b = 2294967295;
669 if (a < b)
670 printf("%ld < %lu: true\n", a, b);
671 else
672 printf("%ld < %lu: false\n", a, b);
673 return 0;
674}
675@endcode
676 * If I understood it correctly, the compiler will convert a to an
677 * unsigned long before doing the compare.
678 *
679 *
680 *
681 * @section sec_vbox_guideline_svn Subversion Commit Rules
682 *
683 *
684 * Before checking in:
685 *
686 * - Check Tinderbox and make sure the tree is green across all platforms. If it's
687 * red on a platform, don't check in. If you want, warn in the \#vbox channel and
688 * help make the responsible person fix it.
689 * NEVER CHECK IN TO A BROKEN BUILD.
690 *
691 * - When checking in keep in mind that a commit is atomic and that the Tinderbox and
692 * developers are constantly checking out the tree. Therefore do not split up the
693 * commit unless it's into 100% independent parts. If you need to split it up in order
694 * to have sensible commit comments, make the sub-commits as rapid as possible.
695 *
696 * - If you make a user visible change, such as fixing a reported bug,
697 * make sure you add an entry to doc/manual/user_ChangeLogImpl.xml.
698 *
699 * - If you are adding files make sure set the right attributes.
700 * svn-ps.sh/cmd was created for this purpose, please make use of it.
701 *
702 *
703 * After checking in:
704 *
705 * - After checking-in, you watch Tinderbox until your check-ins clear. You do not
706 * go home. You do not sleep. You do not log out or experiment with drugs. You do
707 * not become unavailable. If you break the tree, add a comment saying that you're
708 * fixing it. If you can't fix it and need help, ask in the \#innotek channel or back
709 * out the change.
710 *
711 * (Inspired by mozilla tree rules.)
712 */
713
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use