Add the follow to your $HOME/.emacs file:
-```
+```lisp
(add-hook 'c-mode-hook
(lambda ()
(c-set-style "linux")
For the basic vi editor included with all variants of \*nix, add the
following to $HOME/.exrc:
-```
+```vim
set tabstop=8
set shiftwidth=8
```
For Vim, the following settings in $HOME/.vimrc will also deal with
displaying trailing whitespace:
-```
+```vim
if has("syntax") && (&t_Co > 2 || has("gui_running"))
syntax on
function! ActivateInvisibleCharIndicator()
This is good:
-```
+```c
...
int i;
This is bad:
-```
+```c
...
int i;
/*
Use tabs to get as close as possible and then fill in the final 7
characters or less with whitespace. For example,
-```
+```c
var1 = foo(arg1, arg2,
arg3);
```
spaces following or preceding the parentheses in the conditional.
This is good:
-```
+```c
if (x == 1)
```
This is bad:
-```
+```c
if ( x == 1 )
```
Good examples:
-```
+```c
if (x == 1) {
printf("good\n");
}
Bad examples:
-```
+```c
while (1)
{
print("I'm in a loop!\n"); }
Good Examples:
-```
+```c
int function foo(int y)
{
int *z = NULL;
Most of the time a good name for a boolean variable is 'ok'. Here is an
example we often use:
-```
+```c
bool ok;
ok = foo();
Good Example:
-```
+```c
char *pointer1 = NULL;
char *pointer2 = NULL;
Bad Example:
-```
+```c
char *pointer1;
char *pointer2;
Good Example:
-```
+```c
char *name = NULL;
int ret;
Bad Example:
-```
+```c
ret = some_function_my_name(get_some_name());
...
```
Good example:
-```
+```c
x = malloc(sizeof(short)*10);
if (x == NULL) {
fprintf(stderr, "Unable to alloc memory!\n");
Bad example:
-```
+```c
if ((x = malloc(sizeof(short)*10)) == NULL ) {
fprintf(stderr, "Unable to alloc memory!\n");
}
There are exceptions to this rule. One example is walking a data structure in
an iterator style:
-```
+```c
while ((opt = poptGetNextOpt(pc)) != -1) {
... do something with opt ...
}
efficiency because the DBG_ macros don't evaluate their arguments if
the debuglevel is not high enough.
-```
+```c
if (!NT_STATUS_IS_OK(status)) {
struct dom_sid_buf sid_buf;
struct GUID_txt_buf guid_buf;
Don't do this:
-```
+```c
frame = talloc_stackframe();
if (ret == LDB_SUCCESS) {
It should be:
-```
+```c
frame = talloc_stackframe();
if (ret != LDB_SUCCESS) {
Use these following macros instead of DEBUG:
-```
+```c
DBG_ERR log level 0 error conditions
DBG_WARNING log level 1 warning conditions
DBG_NOTICE log level 3 normal, but significant, condition
Example usage:
-```
+```c
DBG_ERR("Memory allocation failed\n");
DBG_DEBUG("Received %d bytes\n", count);
```
Example usage:
-```
+```c
D_DEBUG("Resolving %"PRIu32" SID(s).\n", state->num_sids);
```