Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Patches should be in the form of a unified (-u) diff, made from a checkout from subversion.

Code Blocknoformat
/usr/src/asterisk$ svn diff > mypatch

If you would like to only include changes to certain files in the patch, you can list them in the "svn diff" command:

Code Blocknoformat
/usr/src/asterisk$ svn diff somefile.c someotherfile.c > mypatch


  • Functions and variables that are not intended to be used outside the module must be declared static. If you are compiling on a Linux platform that has the 'dwarves' package available, you can use the 'pglobal' tool from that package to check for unintended global variables or functions being exposed in your object files. Usage is very simple:
No Format

$ pglobal \-vf <path to .o file>
  • When reading integer numeric input with scanf (or variants), do NOT use '%i' unless you specifically want to allow non-base-10 input; '%d' is always a better choice, since it will not silently turn numbers with leading zeros into base-8.


On nearly every 64-bit platform, this will result in 4 bytes of dead space between 'bar' and 'xyz', because pointers on 64-bit platforms must be aligned on 8-byte boundaries. Once you have your code written and tested, it may be worthwhile to review your structure definitions to look for problems of this nature. If you are on a Linux platform with the 'dwarves' package available, the 'pahole' tool from that package can be used to both check for padding issues of this type and also propose reorganized structure definitions to eliminate it. Usage is quite simple; for a structure named 'foo', the command would look something like this:

Code Blocknoformat
$ pahole \--reorganize \--show_reorg_steps \-C foo <path to module>


Roughly, Asterisk code formatting guidelines are generally equivalent to the following:

No Format

\# indent \-i4 \-ts4 \-br \-brs \-cdw \-lp \-ce \-nbfda \-npcs \-nprs \-npsl \-nbbo \-saf \-sai \-saw \-cs \-l90 foo.c

this means in verbose:

No Format
 -i4:    indent level 4
 -ts4:   tab size 4
 -br:    braces on if line
 -brs:   braces on struct decl line
 -cdw:   cuddle do while
 -lp:    line up continuation below parenthesis
 -ce:    cuddle else
 -nbfda: dont break function decl args
 -npcs:  no space after function call names
 -nprs:  no space after parentheses
 -npsl:  dont break procedure type
 -saf:   space after for
 -sai:   space after if
 -saw:   space after while
 -cs:    space after cast
 -l90:  line length 90 columns