Reference GNAQ seniors adults Code Style
Rust style code style:
Pre-compiler directive:
order:
pragma
include
define
undef
indentation:
define undef inherit the upper indented, rest not indented.
Writing:
include the energy use <> try not to use "" ;
include not use spaces.
define undef allows all macro all lowercase or uppercase defined, the remaining cases are not allowed uppercase.
limit:
Do not use #if #else #elif #endif #ifdef #ifndef #endif #line #error and other pre-compile command.
Namespaces:
Writing:
Always use using namespace std or import
- using std::cin
- using std::cout
- using std::endl
- using std::min
- using std::max
Other code appeared std namespace function.
Namespace may be used #define , but must
at the end #undef , and #define instruction should be placed at the beginning of the namespace.
Any large data structures using its abbreviated name of the individual capital namespace , such as the
namespace KDT namespace SGT namespace TRP, and always at the end of a semicolon} namespace suffix ';' , for example:
namespace SGT
{
#define LCH tree[inx].ch[0]
#define RCH tree[inx].ch[1]
void func1()
{
// .....
}
#undef LCH
#undef RCH
};
order:
After all pre-compiler should be placed at the beginning of the instruction code.
indentation:
Inherit the upper indentation.
curly braces:
Writing:
Use $ Allman $-style braces, that braces wrap. E.g:
void Func1()
{
for (;;)
{
// ...
}
if (case)
{
// ....
}
else
{
if (case 2)
{
// ..
}
else { Func2(); return; }
}
}
Without any comma code snippet any ',' operator joins two statements, which format is correct:
for (;;)
{
Func1();
Func2();
}
That is a before and after each pair of curly braces have a have a space between spaces statements.
note:
Only a timely internal statement if and for , etc. must also be enclosed in braces.
Row:
Writing:
Each line must not have multiple (two or more) statements.
Application of the plurality of meaning between the individual code blocks are separated by a blank line;
End of the line should be non-empty redundant spaces;
using namespace std; is followed by a blank line;
Must be separated by a blank line between functions, member functions, structures, global variables block.
if for while other statements, thereafter if only one statement (or nest), can be retracted directly without braces "{}" .
indentation:
Inherit the upper indentation.
Parentheses:
Writing:
In addition parentheses immediately following the declaration and call functions to other characters before and after any pair of parentheses must be a space separated by other characters, such as:
for (;;)
Func1();
if (case1)
{
..
}
int i = (j * 100 + log2(100) );
** if the right parenthesis ")" ** After contact semicolon ';' the space may be omitted.
Pointers and references:
Writing:
The OI $ $ pointer is not used in the code.
References section using Rust -type name, before any reference identifier '&' and separated by a space between the reference variable, if there is pre type identifier, the reference identifier followed type identifier, such as
void Func1(int& q, int& t)
{
int a, b;
int& aref = a, & bref = b;
}
indentation:
Inherit the upper indentation.
function:
Writing:
Nomenclature function using a large hump, optionally added ** underscore '_' **, such as:
void Update()
{
···
}
int Qry()
{
···
}
Mat Gauss_Elimination()
{
···
}
Empty function body must be in the following format:
void Func1() {}
indentation:
Inherit the upper indentation.
Space:
Writing:
Before and after the comma can not have spaces.
Both sides of the colon must have a space.
'+' '-' front / rear without spaces.
The shape vector <pair <int, int>> declaration, each pair <> trailing spaces required symmetry.
'::' '' on both sides with no space.
Before and after the initialization list without spaces, such as max ({A, B, C}); .
indentation:
Inherit the upper indentation.
Comment:
indentation:
Inherit the upper indentation.
Writing:
Single-line comments // use $ $, then there should be a space, such as $ // do something $.
Multi-line comments using $ / * / $, where $ / $, and $ / $ should be on its own line, and $ / post $ and $ * / $ should be a blank line, for example:
int func1()
{
int a=1,b=2;
/*
return 3;
*/
return a+b;
}