CEG221: Advanced C
Programming for Engineers
Class Programming Standard
Naming Conventions:
· Variables
· All pointers must be preceded with a “p”: ie. pPerson
· All members of a struct or union must be preceded by “m”: ie. mName
· Member pointers are preceded by “mp”: ie. mpPerson
· Functions
· All function names start with a lower case letter. Every “word” thereafter begins with a capital letter: ie. doSomething(…), update()
· Variables in function parameter lists should follow the same rules as ordinary variable names
· Data Structures
· All structs and unions should have their name end in “Type”: ie. PersonType
· Enumerated types do not need this, as they are just simply integers
Control Structures
· You must indent for every “{” and un-indent for every “}” (SEE BELOW)
· Curly braces must accompany all if, if/else, if/else chain, while, for, do…while statements and be on separate lines. Example:
if (visible)
{
…
}
· For Boolean statements (ie. p != q) joined by logical operators ( || and &&), you need not have parenthesis around them unless it makes things less confusing. Examples:
· if (p >= 0 && p <= 90) à relatively clear
· if (p >= 0 && p <= 180 && p % 30 == 0) à relatively unclear
· if (p >= 0 && p <= 180 && (p % 30 == 0)) à more clear