Code Style Guide

From Arctic Core - the open source AUTOSAR embedded platform

Jump to: navigation, search

The following rules can be applied to a Arctic Studio (or compatible, such as Eclipse) distribution by downloading the linked file. Code_style.xml

Contents

Indentation rules

We use only spaces in C and H files. An indentation step is 4 spaces.

We try to place the starting curling brackets on the same line as the clause.

Variables and Function Parameters

The Autosar specifications calls reference variables xxRef, types xxType and pointer xxPtr.

Structures should have the members in camelcase and starting with a lowercase letter.

typedef struct {
    uint32_t race;
    _Bool haveArms;
} AnimalType;

Creating the above structure without typedef is made like:

struct Animal {
    uint32_t race;
    _Bool haveArms;
};

For basic type always use use standard types, ie "stdint.h"

uint32_t
uint16_t

Function Parameters

The variable name of a function parameter starts with a lowercase letter just as local variables in the C functions.

void SendData ( uint8_t *dataPtr, uint32_t lengthInBytes); 


Functions

Local:

static void fooBar( void );

Global:

void Module_FooBar( void );

Variables

Local:

 int fooBar;

Global:

 int FooBar;
 

Macros

Always in uppercase letters.

 #define I_HAVE_A_BIG_BELLY     1

Naming of Files and Directories

Adhere to AUTOSAR standard where applicable.

Implementation-specific files and directories are named with lower-case letters to discern from AUTOSAR standard ones.

Naming boards

Lower-case naming. Separate words with underscore where applicable, i.e. mpc5567_qrtech. This helps indexers separate words.

Naming non-AUTOSAR features

Denote non-AUTOSAR features with _ARC_ for macros and _Arc_ for variables, types, structured and functions...

Examples:

void Mcu_Arc_HelloWorld()
#define MCU_ARC_HELLOWORLD_MSG "Hallo welt."