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
typedef enum axis2_status_codes {
AXIS2_FAILURE = 0,
AXIS2_SUCCESS
} axis2_status_codes_t;
2. Indentation
Indentation rules are defined in terms of GNU indent options:
indent -nbad -bap -nbc -bbo -bl -bli0 -bls -ncdb -nce -cp1 -cs -di2
-ndj
-nfc1 -nfca -hnl -i4 -ip5 -lp -pcs -nprs -psl -saf -sai -saw -nsc -nsob
-ts4
-nut -nbfda
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 relavant 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 relavant error
code must also be set
in environment's error struct.
5. Include directives
It is prefereable to include header files in the following fashion:
<standard header files>
<other system headers>
"local header files"