Axis2/C Coding Conventions

1. Naming conventions

  • Namespace validation is done using the axis2_ prefix.
  • Underscore should be used to separate individual words in identifiers.
  • All identifiers should be meaningful and abbreviations must be avoided whenever possible.

1.1 Variables

  • Use meaningful nouns.
  • Make sure to use all lowercase letters for private & public variables.
  • If it is a local variable or a member of a struct, there's no need to prefix it with axis2_.
  • e.g.
    int count = 0;

    char *prefix = NULL;

1.2 Functions

  • Function names should always start with the prefix axis2_ except for members of a struct.
  • e.g.

    axis2_om_node_t * axis2_om_node_create(axis2_environment_t *environment);

1.3 Structures and user defined data types

  • Note the _t suffix in the type name.
  • e.g.
    typedef struct axis2_om_namespace {

    char *uri;

    char *prefix;

    } axis2_om_namespace_t;

1.4 Macros

  • Macro names should be in all uppercase letters.
  • e.g.
    #define AXIS2_H



    #define AXIS2_ERROR_GET_MESSAGE(error) ((error)->ops->get_message(error))

1.5 Enumerations

    e.g.
    typedef enum axis2_status_codes {

    AXIS2_FAILURE = 0,

    AXIS2_SUCCESS

    } axis2_status_codes_t;

2. Indentation and Formatting

    Indentation rules are defined in terms of Artistic Style indent options:
    astyle --style=ansi -b -p -s4 -M0 -c -U -S
    In detail, these options mean:
    • Use ANSI style code layout
                  int foo()
                  {
                      if (is_bar)
                      {
                          bar();
                          return 1;
                      }
                      else
                          return 0;
                  }
                  
    • Use spaces around operators
    • Use four spaces for indenting
    • No spaces between function name and parenthesis
                  if (is_foo(a, b))
                      bar(a, b);
                  
              
    There are some more formatting guidelines that could not be enforced by a formatting tool, but nevertheless should be followed
    • Checking pointer validity:
                  if (foo)
                  
      and NOT
                  if (foo != NULL)
                  
    • Checking equality:
                  if (foo == 7)
                  
      and NOT
                  if (7 == foo)
                  

3. Comments

    Doxygen style comments should be used to help auto generate API documentation. All structs as well as functions including parameters and return types should be documented.

4. Function parameters and Return Value conventions

    Each function should be passed a pointer to an instance of axis2_environment_t struct as the first parameter. If the function is tightly bound to a struct, the second parameter is a pointer to an instance of that struct.
    Functions returning pointers should return NULL in case of an error. The developer should make sure to set the relevant error code in the environment's error struct.
    Functions returning none pointer values should always return AXIS2_FAILURE status code on error whenever possible, or some defined error value (in case of returning a struct may be). A relevant error code must also be set in environment's error struct.

5. Include directives

    It is preferable to include header files in the following fashion:
    <standard header files>

    <other system headers>

    "local header files"