coderules.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. IJG JPEG LIBRARY: CODING RULES
  2. This file was part of the Independent JPEG Group's software:
  3. Copyright (C) 1991-1996, Thomas G. Lane.
  4. It was modified by The libjpeg-turbo Project to include only information
  5. relevant to libjpeg-turbo.
  6. For conditions of distribution and use, see the accompanying README.ijg file.
  7. Since numerous people will be contributing code and bug fixes, it's important
  8. to establish a common coding style. The goal of using similar coding styles
  9. is much more important than the details of just what that style is.
  10. In general we follow the recommendations of "Recommended C Style and Coding
  11. Standards" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and
  12. Brader). This document is available in the IJG FTP archive (see
  13. jpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl).
  14. Block comments should be laid out thusly:
  15. /*
  16. * Block comments in this style.
  17. */
  18. We indent statements in K&R style, e.g.,
  19. if (test) {
  20. then-part;
  21. } else {
  22. else-part;
  23. }
  24. with two spaces per indentation level. (This indentation convention is
  25. handled automatically by GNU Emacs and many other text editors.)
  26. Multi-word names should be written in lower case with underscores, e.g.,
  27. multi_word_name (not multiWordName). Preprocessor symbols and enum constants
  28. are similar but upper case (MULTI_WORD_NAME). Names should be unique within
  29. the first fifteen characters.
  30. Note that each function definition must begin with GLOBAL(type), LOCAL(type),
  31. or METHODDEF(type). These macros expand to "static type" or just "type" as
  32. appropriate. They provide a readable indication of the routine's usage and
  33. can readily be changed for special needs. (For instance, special linkage
  34. keywords can be inserted for use in Windows DLLs.)
  35. A similar solution is used for external function declarations (see the EXTERN
  36. macro.)
  37. The JPEG library is intended to be used within larger programs. Furthermore,
  38. we want it to be reentrant so that it can be used by applications that process
  39. multiple images concurrently. The following rules support these requirements:
  40. 1. Avoid direct use of file I/O, "malloc", error report printouts, etc;
  41. pass these through the common routines provided.
  42. 2. Minimize global namespace pollution. Functions should be declared static
  43. wherever possible. (Note that our method-based calling conventions help this
  44. a lot: in many modules only the initialization function will ever need to be
  45. called directly, so only that function need be externally visible.) All
  46. global function names should begin with "jpeg_".
  47. 3. Don't use global variables; anything that must be used in another module
  48. should be in the common data structures.
  49. 4. Don't use static variables except for read-only constant tables. Variables
  50. that should be private to a module can be placed into private structures (see
  51. the system architecture document, structure.txt).
  52. 5. Source file names should begin with "j" for files that are part of the
  53. library proper; source files that are not part of the library, such as cjpeg.c
  54. and djpeg.c, do not begin with "j". Keep compression and decompression code in
  55. separate source files --- some applications may want only one half of the
  56. library.
  57. Note: these rules (particularly #4) are not followed religiously in the
  58. modules that are used in cjpeg/djpeg but are not part of the JPEG library
  59. proper. Those modules are not really intended to be used in other
  60. applications.