-
Notifications
You must be signed in to change notification settings - Fork 10
Code style
perberos edited this page Nov 9, 2011
·
2 revisions
I should like to use Allman (ANSI) style. Long line is fine too. Recommended tab width is 4, but MATE code style allow you to set any you want. 2 or 8 by example.
Use pointers at the left size.
void* custom_function(char* name);int* address = (void*) custom_function((char*) unknown_string);#define SOME_TYPE_DEF (a) // replace SOME_TYPE_DEF with (a)#define SOME_TYPE_DEF(a) // replace SOME_TYPE_DEF(a) with noneSo this functions should be easy to understand
// define prototype
long int mycustom_someclass_somefunction(char a);
// define block code
long int mycustom_someclass_somefunction(char a)
{
return (long int) some_function(a);
}Use what ever you want.
if (declaration_is_true(some_value))
{
static char b; // <tab> <spaces>
int a; // <tab> <spaces>
unsigned int some_long_value; // <tab> <spaces>
struct my_custom_struct some_misterious_struct;large declaration show you how much stack use a funcion, so deal with it. Next code is right.
char* omg_my_application_do_all(struct some_custom_struc* object, int* height, int* width, int* x, int* y, char* title, char* tooltip, char* description, char* sub_description, int flags)
{
// ...but you can use code like block on #define
#define SOME_MACRO_WITH_FUNCTION(x, y, z) \
{ \
long dist = x * y * z; \
if (dist <= 0) \
{ \
dist = 1; \
err = DIST_IS_ZERO; \
} \
prev_defined = dist; \
}Do not use tab, use 4 spaces. 2 is slightly, 8 is much. Alignment of arguments is allowed.
If you want copy paste a code and run into a shell, terminal take the tab key and will try to autocomplete some words.