SDCC coding style - roybaer/sdcc-wiki GitHub Wiki

Table of Contents

SDCC C and C++ coding style

You can find many different coding styles in SDCC sources.
The preferred coding style is the one described in GNU Coding Standards document, 5.1 Formatting Your Source Code chapter.

Additional SDCC specific rules:

  • indent size = 2
  • tab size = 8
  • don't use tab characters in the source code, use spaces instead.
  • do not commit purely stylistic changes as that would break the file history, which is worse than an inconsistent style. Instead consider fixing the style of individual subroutines when fixing the code itself as well.

Recommended Vim options:

To have Vim automatically format your code close to the desired coding style, add the following fragment to your $HOME/.vimrc (Unix) or $HOME/_vimrc (Windows):

function SetupSDCC()
  " Follow SDCC coding style
  set tabstop=8
  set softtabstop=2
  set expandtab
  set cindent
  set formatoptions=tcroq
  set shiftwidth=4
  set cinoptions=n-2,^-2,{2,l1,t0,(0
endfunction

filetype on
autocmd FileType c,cpp call SetupSDCC()

Formatting with indent and astyle utilities:

The following commands reformat the source file in compliance with the preferred coding style:

  • for C sources:
indent --line-length128 --no-tabs <source_file>
  • for C and C++ sources:
astyle --style=gnu --pad-oper --pad-header --indent=spaces=2 --convert-tabs <source_file>

sdas and sdld coding style

sdas and sdld (SDCC assembler and linker) source files are using different coding syle then SDCC:

  • indent size = 8
  • tab size = 8
  • use tab characters instead spaces where applicable in the source code
This is due that sdas and sdld are derived from ASXXXX and we want to keep the differences as small as possible in order to keep the merging simple.

ChangeLog coding style

All changes should be documented in the GNU style ChangeLog.

Additional SDCC specific rules:

  • use the TAB character for indentation.
  • follow the style of previous ChangeLog entries
  • don't forget to thank the author when applying a patch

SDCC library source file license header

See SDCC library source file license header.

SVN commits

Add the commit comments when committing changes to the Subversion repository. Comments are usually same as ChangeLog entries with the leading TAB characters removed. For example see previous commit comments:

svn log &lt;file_name&gt;

SVN config settings

Use svn:eol-style=native attribute for newly added textual files to the SDCC svn repository.
The preferred method is to apply the following settings to the svn conf file, located at:

  • Windows: C:\Documents and Settings\YourUserName\Application Data\Subversion\config
  • Linux: ~/.subversion/config
### This file configures various client-side behaviors.
###
### The commented-out examples below are intended to demonstrate
### how to use this file.

### Section for authentication and authorization customizations.
# [auth]
### Set store-passwords to 'no' to avoid storing passwords in the
### auth/ area of your config directory.  It defaults to 'yes'.
### Note that this option only prevents saving of *new* passwords;
### it doesn't invalidate existing passwords.  (To do that, remove
### the cache files by hand as described in the Subversion book.)
# store-passwords = no
### Set store-auth-creds to 'no' to avoid storing any subversion
### credentials in the auth/ area of your config directory.
### It defaults to 'yes'.  Note that this option only prevents
### saving of *new* credentials;  it doesn't invalidate existing
### caches.  (To do that, remove the cache files by hand.)
# store-auth-creds = no

### Section for configuring external helper applications.
### Set editor to the command used to invoke your text editor.
###   This will override the environment variables that Subversion
###   examines by default to find this information ($EDITOR,
###   et al).
### Set diff-cmd to the absolute path of your 'diff' program.
###   This will override the compile-time default, which is to use
###   Subversion's internal diff implementation.
### Set diff3-cmd to the absolute path of your 'diff3' program.
###   This will override the compile-time default, which is to use
###   Subversion's internal diff3 implementation.
### Set diff3-has-program-arg to 'true' or 'yes' if your 'diff3'
###   program accepts the '--diff-program' option.
# [helpers]
# editor-cmd = editor (vi, emacs, notepad, etc.)
# diff-cmd = diff_program (diff, gdiff, etc.)
# diff3-cmd = diff3_program (diff3, gdiff3, etc.)
# diff3-has-program-arg = [true | false]

### Section for configuring tunnel agents.
# [tunnels]
### Configure svn protocol tunnel schemes here.  By default, only
### the 'ssh' scheme is defined.  You can define other schemes to
### be used with 'svn+scheme://hostname/path' URLs.  A scheme
### definition is simply a command, optionally prefixed by an
### environment variable name which can override the command if it
### is defined.  The command (or environment variable) may contain
### arguments, using standard shell quoting for arguments with
### spaces.  The command will be invoked as:
###   <command> <hostname> svnserve -t
### (If the URL includes a username, then the hostname will be
### passed to the tunnel agent as <user>@<hostname>.)  If the
### built-in ssh scheme were not predefined, it could be defined
### as:
# ssh = $SVN_SSH ssh
### If you wanted to define a new 'rsh' scheme, to be used with
### 'svn+rsh:' URLs, you could do so as follows:
# rsh = rsh
### Or, if you wanted to specify a full path and arguments:
# rsh = /path/to/rsh -l myusername
### On Windows, if you are specifying a full path to a command,
### use a forward slash (/) or a paired backslash (\\) as the
### path separator.  A single backslash will be treated as an
### escape for the following character.

### Section for configuring miscelleneous Subversion options.
[miscellany]
### Set global-ignores to a set of whitespace-delimited globs
### which Subversion will ignore in its 'status' output.
# global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store
### Set log-encoding to the default encoding for log messages
# log-encoding = latin1
### Set use-commit-times to make checkout/update/switch/revert
### put last-committed timestamps on every file touched.
# use-commit-times = yes
### Set enable-auto-props to 'yes' to enable automatic properties
### for 'svn add' and 'svn import', it defaults to 'no'.
### Automatic properties are defined in the section 'auto-props'.
enable-auto-props = yes

### Section for configuring automatic properties.
### The format of the entries is:
###   file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?').  All entries which match will be applied to the file.
### Note that auto-props functionality must be enabled, which
### is typically done by setting the 'enable-auto-props' option.
[auto-props]
*.c = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.cc = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.cpp = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.h = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.hpp = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.dsp = svn:eol-style=CRLF
*.dsw = svn:eol-style=CRLF
*.sh = svn:eol-style=native;svn:executable;svn:keywords=Author Date Id Revision
*.txt = svn:eol-style=native
*.png = svn:mime-type=image/png
*.jpg = svn:mime-type=image/jpeg
*.ico = svn:mime-type=image/ico
*.htm = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.html = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.pl = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.pm = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.mk = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.m4 = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.in = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.js = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.php = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.py = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.lkr = svn:eol-style=native;svn:keywords=Author Date Id Revision
*.inc = svn:eol-style=native;svn:keywords=Author Date Id Revision
configure = svn:eol-style=native;svn:keywords=Author Date Id Revision
Makefile = svn:eol-style=native
ChangeLog = svn:eol-style=native;svn:keywords=Author Date Id Revision

Borut

⚠️ **GitHub.com Fallback** ⚠️