/**
* \defgroup coding-style Coding style
*
* This is how a Doxygen module is documented - start with a \defgroup
* Doxygen keyword at the beginning of the file to define a module,
* and use the \addtogroup Doxygen keyword in all other files that
* belong to the same module. Typically, the \defgroup is placed in
* the .h file and \addtogroup in the .c file.
*
* @{
*/ /**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@dunkels.com>
*
* Every file that is part of a documented module has to have
* a \file block, else it will not show up in the Doxygen
* "Modules" * section.
*/ /* Single line comments look like this. */ /*
* Multi-line comments look like this. Comments should prefferably be
* full sentences, filled to look like real paragraphs.
*/ #include "contiki.h" /*
* Make sure that non-global variables are all maked with the static
* keyword. This keeps the size of the symbol table down.
*/
static int flag; /*
* All variables and functions that are visible outside of the file
* should have the module name prepended to them. This makes it easy
* to know where to look for function and variable definitions.
*
* Put dividers (a single-line comment consisting only of dashes)
* between functions.
*/
/*---------------------------------------------------------------------------*/
/**
* \brief Use Doxygen documentation for functions.
* \param c Briefly describe all parameters.
* \return Briefly describe the return value.
* \retval 0 Functions that return a few specified values
* \retval 1 can use the \retval keyword instead of \return.
*
* Put a longer description of what the function does
* after the preamble of Doxygen keywords.
*
* This template should always be used to document
* functions. The text following the introduction is used
* as the function's documentation.
*
* Function prototypes have the return type on one line,
* the name and arguments on one line (with no space
* between the name and the first parenthesis), followed
* by a single curly bracket on its own line.
*/
void
code_style_example_function(void)
{
/*
* Local variables should always be declared at the start of the
* function.
*/
int i; /* Use short variable names for loop
counters. */ /*
* There should be no space between keywords and the first
* parenthesis. There should be spaces around binary operators, no
* spaces between a unary operator and its operand.
*
* Curly brackets following for(), if(), do, and case() statements
* should follow the statement on the same line.
*/
for(i = ; i < ; ++i) {
/*
* Always use full blocks (curly brackets) after if(), for(), and
* while() statements, even though the statement is a single line
* of code. This makes the code easier to read and modifications
* are less error prone.
*/
if(i == c) {
return c; /* No parentesis around return values. */
} else { /* The else keyword is placed inbetween
curly brackers, always on its own line. */
c++;
}
}
}
/*---------------------------------------------------------------------------*/
/*
* Static (non-global) functions do not need Doxygen comments. The
* name should not be prepended with the module name - doing so would
* create confusion.
*/
static void
an_example_function(void)
{ }
/*---------------------------------------------------------------------------*/ /* The following stuff ends the \defgroup block at the beginning of
the file: */ /** @} */

contiki/docs/code-style.c

一、模块 :

\defgroup 定义一个模块,一般在.h文件。

/** @} */ 和@{对应。

\addtogroup 加到某个模块,一般在.c文件。

/** @} */ 和@{对应。

\file 文件,每个需要生成文档的文件,都要添加这个标号。

/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@dunkels.com>
*
* Every file that is part of a documented module has to have
* a \file block, else it will not show up in the Doxygen
* "Modules" * section.
*/

二、变量

不是全局变量的要添加static,限于该文件可见。

/*
* Make sure that non-global variables are all maked with the static
* keyword. This keeps the size of the symbol table down.
*/
static int flag;

局部变量要在函数statement之前定义

  /*
* Local variables should always be declared at the start of the
* function.
*/
int i; /* Use short variable names for loop
counters. */

三、函数

函数或者变量,对外可见的话,要在函数名前添加模块名,这样可方便知道到哪查看函数或变量的定义。

函数和函数之间用一行只有-的注释来分隔开。

/*
* All variables and functions that are visible outside of the file
* should have the module name prepended to them. This makes it easy
* to know where to look for function and variable definitions.
*
* Put dividers (a single-line comment consisting only of dashes)
* between functions.
*/
/*---------------------------------------------------------------------------*/

函数原型及功能说明

返回值在一行

名字和参数在一行,第一个参数和 '('  不用空格隔开

下一行为{

/**
* \brief Use Doxygen documentation for functions.
* \param c Briefly describe all parameters.
* \return Briefly describe the return value.
* \retval 0 Functions that return a few specified values
* \retval 1 can use the \retval keyword instead of \return.
*
* Put a longer description of what the function does
* after the preamble of Doxygen keywords.
*
* This template should always be used to document
* functions. The text following the introduction is used
* as the function's documentation.
*
* Function prototypes have the return type on one line,
* the name and arguments on one line (with no space
* between the name and the first parenthesis), followed
* by a single curly bracket on its own line.
*/

静态函数不用添加文档注释,也不要添加模块名字,因为静态函数只在本文件可见。

四、语句

关键词和第一个 ‘(’ 不用空格隔开

二元操作符要有空格隔开

一元操作符不用空格隔开

‘{’ 要和 if() for() do case() 等语句在同一行

在 if() for() while() 等语句后都要添加{},即使只有一行代码,方便阅读和后续修改。

else要被 } { 包围,并自同一行

/*
* There should be no space between keywords and the first
* parenthesis. There should be spaces around binary operators, no
* spaces between a unary operator and its operand.
*
* Curly brackets following for(), if(), do, and case() statements
* should follow the statement on the same line.
*/
for(i = ; i < ; ++i) {
/*
* Always use full blocks (curly brackets) after if(), for(), and
* while() statements, even though the statement is a single line
* of code. This makes the code easier to read and modifications
* are less error prone.
*/
if(i == c) {
return c; /* No parentesis around return values. */
} else { /* The else keyword is placed inbetween
curly brackers, always on its own line. */
c++;
}
}
}

Contiki 源码风格的更多相关文章

  1. Contiki源码+原理+功能+编程+移植+驱动+网络(转)

    源:Contiki源码+原理+功能+编程+移植+驱动+网络 请链接:http://www.rimelink.com/nd.jsp? id=31&_np=105_315 假设您对于用Contik ...

  2. Contiki源码结构

    Contiki源码结构 apps目录下,用于存放Application,也就是我们的应用程序放在这个目录下.如webserver,webrowser等,如下图所示. core目录是contiki操作系 ...

  3. contiki源码阅读之list

    我们阅读一下contiki的源码,list.c(路径是./core/lib/list.h). #include "lib/list.h" #define NULL 0 struct ...

  4. Backbone源码风格

         代码风格: 一.自执行匿名函数创建执行环境 var root = this; root保存全局执行环境的指针.浏览器端为window对象 二.依赖库 (1).underscore 如果bac ...

  5. Contiki源码分析--CPU为cc253x里的uart0.c

    我所使用的Contiki系统是contiki-sensinode.理解该文需要有cc2530里uart的相关知识,具体寄存器的用法不做介绍. 先放上所有代码,然后再仔细分析. #include < ...

  6. contiki源码阅读之mmem.c

    上次我们说了list,这次我们就借着mmem.c的代码来用一下这个链表. 代码目录是./core/lib/mmem.c 结构体定义如下 struct mmem { struct mmem *next; ...

  7. Google之Chromium浏览器源码学习——base公共通用库(一)

    Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...

  8. 卡通风格的连连看ios游戏源码

    卡通风格的连连看游戏源码,该游戏是一款韩国人做的卡通风格的ios连连看游戏源码,源码设计的效果非常漂亮的,而且运行起来感觉也很好.1.游戏采用倒计时模式2.该游戏是一款社交游戏,需要通过faceboo ...

  9. arcgis api 3.x for js 共享干货系列之二自定义 Navigation 控件样式风格(附源码下载)

    0.内容概览 自定义 Navigation 控件样式风格 源码下载 1.内容讲解 arcgis api 3.x for js 默认的Navigation控件样式风格如下图:这样的风格不能说不好,各有各 ...

随机推荐

  1. 2016.6.21 -Dmaven.multiModuleProjectDirectory system propery is not set,Check $M2_HOME environment variable and mvn script match.

    eclipse中使用maven插件的时候,运行run as maven build的时候报错: -Dmaven.multiModuleProjectDirectory system propery i ...

  2. .NET中XML 注释 SandCastle 帮助文件.hhp 使用HTML Help Workshop生成CHM文件

    一.摘要 在本系列的第一篇文章介绍了.NET中XML注释的用途, 本篇文章将讲解如何使用XML注释生成与MSDN一样的帮助文件.主要介绍NDoc的继承者:SandCastle. .SandCastle ...

  3. 从头认识java-14.2 进一步了解数组

    这一章节我们来全面了解一下数组. 1.数组在初始化之前.我们不能使用他的引用来做不论什么事情. package com.ray.ch14; public class Test { public sta ...

  4. 未经处理的异常在 System.Data.dll 中发生。其它信息:在应使用条件的上下文(在 &#39;***&#39; 附近)中指定了非布尔类型的表达式。

    机房收费系统中,有些人在联合查询这个模块用的是存储过程.我先尝试着在数据库中建立了一个视图.然后在UI层做个推断并生成查询条件strCondition. 在机房收费系统的"联合查询" ...

  5. hosts.allow、hosts.deny无效查看服务是否支持tcp_Wrappers

    通过配置hosts.allow.hosts.deny,控制SSH限制固定IP登陆 按照以往的方法,分别在hosts.allow.hosts.deny加入以下配置 # more /etc/hosts.a ...

  6. CDH集群集成kafka

    搭建要求: 1.CDH环境已经搭建成功,在CDH上搭建kafka.要求用CDH上zookeeper管理kafka而不用kafka自带的zookeeper 2.kafka_2.11-0.8.2.1.tg ...

  7. 【Python】使用类和实例

    Car类 class Car(): '''模拟汽车''' def __init__(self,name,model,year): '''初始化汽车的属性''' self.name = name sel ...

  8. OJ刷题---ASCII码排序

    题目要求: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluaGFpeXVuX3l0ZHg=/font/5a6L5L2T/fontsize/400/f ...

  9. 16进制颜色转换为UIColor

    objc #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >& ...

  10. iOS中UDP的使用

    // //  ViewController.m //  UDPDemo // //  Created by qianfeng01 on 15-8-13. //  Copyright (c) 2015年 ...