Skip to content

Code Style

Sukant Pal edited this page Nov 1, 2017 · 9 revisions

The CircuitKernel uses a specific coding style which is uncommon among the C programmers.

C & C++ Integration

Although the kernel is built using C++, the C coding style is allowed (for non-core code) and is supported using function-attribute macros -

decl_c ret_type PlainCFunctionName(args);
import_asm ret_type PlainAsmFunctionName(args);
export_asm ret_type PlainCFunctionName(args);

Here,

  • decl_c means the function is to declared in "C" style and to be used in *.c files.
  • import_asm means the function is implemented in assembly files.
  • export_asm means the function will be used by assembly files.

Structures

A structure is always typedef-ed, if it is abstract, and is declared as -

/**
 * Struct: DataTypeName / Type: ABSTRACT_TYPE
 * Attributes: file-only (iff not in header)
 *
 * Summary:
 * blah-blah-blah
 *
 * Version: x.y.z
 * Since: Circuit X.xy,++
 * Author: Shukant Pal
 */
struct DataTypeName {
     VAR_TYPE variableName;
     struct ChildStruct otherStruct;
} ABSTRACT_TYPE;/* Used only if the type is opaque! */

Structures are a fundamental part of the coding style, as only they are supported in data structures. The kernel does not (like) use of templates for widely-used classes, thus, the Void *pointer (instead of template-types). All stuff that needs to be stored in a data structure should be organized into a struct declaration.

Global Functions

A global function is defined as

 function_attribute retType PlainCFunctionName(args);

All function names are written in PascalCase for differentiating with C++ class functions which are in camelCase.

Class Definition

A class is defined as (source or header) -

  /**
   * Class: ClassName
   *
   * Summary:
   * This class implements the management of ....
   *
   * Important Functions:
   * functionName - 
   *
   * Version: Version of class
   * Since: Circuit x.yz,++
   * Author: Implementor's Name
   */
   class ClassName {
   public:
       varType variable;
       retType functionName(args);
   private:
   };

Function Declaration

A function is declared differently than definition -

   /**
    * Function: Class::function OR Function: CGlobalFunction
    *
    * Summary:
    * What does it do? Why does it do?
    *
    * Effects:
    * Changes to be noted by client
    *
    * Changes:
    * Changes done to implementation recently
    *
    * NOTE:
    * Any special notes
    *
    * Version:
    * Since:
    * Author:
    */
   retType functionName(
                    argType argName, // 2-indentations b/w function & args
   ){

   }
Clone this wiki locally